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 <unistd.h> 12 #include <inttypes.h> 13 #include <sys/queue.h> 14 15 #include <rte_common.h> 16 #include <rte_byteorder.h> 17 #include <rte_log.h> 18 #include <rte_debug.h> 19 #include <rte_cycles.h> 20 #include <rte_memory.h> 21 #include <rte_memzone.h> 22 #include <rte_malloc.h> 23 #include <rte_launch.h> 24 #include <rte_eal.h> 25 #include <rte_per_lcore.h> 26 #include <rte_lcore.h> 27 #include <rte_branch_prediction.h> 28 #include <rte_ring.h> 29 #include <rte_mempool.h> 30 #include <rte_interrupts.h> 31 #include <rte_pci.h> 32 #include <rte_ether.h> 33 #include <rte_ethdev.h> 34 #include <rte_string_fns.h> 35 #include <rte_devargs.h> 36 #include <rte_flow.h> 37 #ifdef RTE_LIB_GRO 38 #include <rte_gro.h> 39 #endif 40 #include <rte_mbuf_dyn.h> 41 42 #include <cmdline_rdline.h> 43 #include <cmdline_parse.h> 44 #include <cmdline_parse_num.h> 45 #include <cmdline_parse_string.h> 46 #include <cmdline_parse_ipaddr.h> 47 #include <cmdline_parse_etheraddr.h> 48 #include <cmdline_socket.h> 49 #include <cmdline.h> 50 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA 51 #include <rte_pmd_dpaa.h> 52 #endif 53 #ifdef RTE_NET_IXGBE 54 #include <rte_pmd_ixgbe.h> 55 #endif 56 #ifdef RTE_NET_I40E 57 #include <rte_pmd_i40e.h> 58 #endif 59 #ifdef RTE_NET_BNXT 60 #include <rte_pmd_bnxt.h> 61 #endif 62 #include "testpmd.h" 63 #include "cmdline_mtr.h" 64 #include "cmdline_tm.h" 65 #include "bpf_cmd.h" 66 67 static struct cmdline *testpmd_cl; 68 static cmdline_parse_ctx_t *main_ctx; 69 static TAILQ_HEAD(, testpmd_driver_commands) driver_commands_head = 70 TAILQ_HEAD_INITIALIZER(driver_commands_head); 71 72 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue); 73 74 /* *** Help command with introduction. *** */ 75 struct cmd_help_brief_result { 76 cmdline_fixed_string_t help; 77 }; 78 79 static void cmd_help_brief_parsed(__rte_unused void *parsed_result, 80 struct cmdline *cl, 81 __rte_unused void *data) 82 { 83 cmdline_printf( 84 cl, 85 "\n" 86 "Help is available for the following sections:\n\n" 87 " help control : Start and stop forwarding.\n" 88 " help display : Displaying port, stats and config " 89 "information.\n" 90 " help config : Configuration information.\n" 91 " help ports : Configuring ports.\n" 92 " help registers : Reading and setting port registers.\n" 93 " help filters : Filters configuration help.\n" 94 " help traffic_management : Traffic Management commands.\n" 95 " help devices : Device related commands.\n" 96 " help drivers : Driver specific commands.\n" 97 " help all : All of the above sections.\n\n" 98 ); 99 100 } 101 102 static cmdline_parse_token_string_t cmd_help_brief_help = 103 TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help"); 104 105 static cmdline_parse_inst_t cmd_help_brief = { 106 .f = cmd_help_brief_parsed, 107 .data = NULL, 108 .help_str = "help: Show help", 109 .tokens = { 110 (void *)&cmd_help_brief_help, 111 NULL, 112 }, 113 }; 114 115 /* *** Help command with help sections. *** */ 116 struct cmd_help_long_result { 117 cmdline_fixed_string_t help; 118 cmdline_fixed_string_t section; 119 }; 120 121 static void cmd_help_long_parsed(void *parsed_result, 122 struct cmdline *cl, 123 __rte_unused void *data) 124 { 125 int show_all = 0; 126 struct cmd_help_long_result *res = parsed_result; 127 128 if (!strcmp(res->section, "all")) 129 show_all = 1; 130 131 if (show_all || !strcmp(res->section, "control")) { 132 133 cmdline_printf( 134 cl, 135 "\n" 136 "Control forwarding:\n" 137 "-------------------\n\n" 138 139 "start\n" 140 " Start packet forwarding with current configuration.\n\n" 141 142 "start tx_first\n" 143 " Start packet forwarding with current config" 144 " after sending one burst of packets.\n\n" 145 146 "stop\n" 147 " Stop packet forwarding, and display accumulated" 148 " statistics.\n\n" 149 150 "quit\n" 151 " Quit to prompt.\n\n" 152 ); 153 } 154 155 if (show_all || !strcmp(res->section, "display")) { 156 157 cmdline_printf( 158 cl, 159 "\n" 160 "Display:\n" 161 "--------\n\n" 162 163 "show port (info|stats|summary|xstats|fdir|dcb_tc) (port_id|all)\n" 164 " Display information for port_id, or all.\n\n" 165 166 "show port info (port_id) representor\n" 167 " Show supported representors for a specific port\n\n" 168 169 "show port port_id (module_eeprom|eeprom)\n" 170 " Display the module EEPROM or EEPROM information for port_id.\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 (port_id) rss-hash [key]\n" 178 " Display the RSS hash functions and RSS hash key of port\n\n" 179 180 "clear port (info|stats|xstats|fdir) (port_id|all)\n" 181 " Clear information for port_id, or all.\n\n" 182 183 "show (rxq|txq) info (port_id) (queue_id)\n" 184 " Display information for configured RX/TX queue.\n\n" 185 186 "show config (rxtx|cores|fwd|rxoffs|rxpkts|txpkts)\n" 187 " Display the given configuration.\n\n" 188 189 "read rxd (port_id) (queue_id) (rxd_id)\n" 190 " Display an RX descriptor of a port RX queue.\n\n" 191 192 "read txd (port_id) (queue_id) (txd_id)\n" 193 " Display a TX descriptor of a port TX queue.\n\n" 194 195 "show vf stats (port_id) (vf_id)\n" 196 " Display a VF's statistics.\n\n" 197 198 "clear vf stats (port_id) (vf_id)\n" 199 " Reset a VF's statistics.\n\n" 200 201 "show port meter stats (port_id) (meter_id) (clear)\n" 202 " Get meter stats on a port\n\n" 203 204 "show fwd stats all\n" 205 " Display statistics for all fwd engines.\n\n" 206 207 "clear fwd stats all\n" 208 " Clear statistics for all fwd engines.\n\n" 209 210 "show port (port_id) rx_offload capabilities\n" 211 " List all per queue and per port Rx offloading" 212 " capabilities of a port\n\n" 213 214 "show port (port_id) rx_offload configuration\n" 215 " List port level and all queue level" 216 " Rx offloading configuration\n\n" 217 218 "show port (port_id) tx_offload capabilities\n" 219 " List all per queue and per port" 220 " Tx offloading capabilities of a port\n\n" 221 222 "show port (port_id) tx_offload configuration\n" 223 " List port level and all queue level" 224 " Tx offloading configuration\n\n" 225 226 "show port (port_id) tx_metadata\n" 227 " Show Tx metadata value set" 228 " for a specific port\n\n" 229 230 "show port (port_id) ptypes\n" 231 " Show port supported ptypes" 232 " for a specific port\n\n" 233 234 "show device info (<identifier>|all)" 235 " Show general information about devices probed.\n\n" 236 237 "show port (port_id) rxq|txq (queue_id) desc (desc_id) status" 238 " Show status of rx|tx descriptor.\n\n" 239 240 "show port (port_id) rxq (queue_id) desc used count\n" 241 " Show current number of filled receive" 242 " packet descriptors.\n\n" 243 244 "show port (port_id) macs|mcast_macs" 245 " Display list of mac addresses added to port.\n\n" 246 247 "show port (port_id) flow transfer proxy\n" 248 " Display proxy port to manage transfer flows\n\n" 249 250 "show port (port_id) fec capabilities" 251 " Show fec capabilities of a port.\n\n" 252 253 "show port (port_id) fec_mode" 254 " Show fec mode of a port.\n\n" 255 256 "show port (port_id) flow_ctrl" 257 " Show flow control info of a port.\n\n" 258 ); 259 } 260 261 if (show_all || !strcmp(res->section, "config")) { 262 cmdline_printf( 263 cl, 264 "\n" 265 "Configuration:\n" 266 "--------------\n" 267 "Configuration changes only become active when" 268 " forwarding is started/restarted.\n\n" 269 270 "set default\n" 271 " Reset forwarding to the default configuration.\n\n" 272 273 "set verbose (level)\n" 274 " Set the debug verbosity level X.\n\n" 275 276 "set log global|(type) (level)\n" 277 " Set the log level.\n\n" 278 279 "set nbport (num)\n" 280 " Set number of ports.\n\n" 281 282 "set nbcore (num)\n" 283 " Set number of cores.\n\n" 284 285 "set coremask (mask)\n" 286 " Set the forwarding cores hexadecimal mask.\n\n" 287 288 "set portmask (mask)\n" 289 " Set the forwarding ports hexadecimal mask.\n\n" 290 291 "set burst (num)\n" 292 " Set number of packets per burst.\n\n" 293 294 "set burst tx delay (microseconds) retry (num)\n" 295 " Set the transmit delay time and number of retries," 296 " effective when retry is enabled.\n\n" 297 298 "set rxoffs (x[,y]*)\n" 299 " Set the offset of each packet segment on" 300 " receiving if split feature is engaged." 301 " Affects only the queues configured with split" 302 " offloads.\n\n" 303 304 "set rxpkts (x[,y]*)\n" 305 " Set the length of each segment to scatter" 306 " packets on receiving if split feature is engaged." 307 " Affects only the queues configured with split" 308 " offloads.\n\n" 309 310 "set txpkts (x[,y]*)\n" 311 " Set the length of each segment of TXONLY" 312 " and optionally CSUM packets.\n\n" 313 314 "set txsplit (off|on|rand)\n" 315 " Set the split policy for the TX packets." 316 " Right now only applicable for CSUM and TXONLY" 317 " modes\n\n" 318 319 "set txtimes (x, y)\n" 320 " Set the scheduling on timestamps" 321 " timings for the TXONLY mode\n\n" 322 323 "set corelist (x[,y]*)\n" 324 " Set the list of forwarding cores.\n\n" 325 326 "set portlist (x[,y]*)\n" 327 " Set the list of forwarding ports.\n\n" 328 329 "set port setup on (iterator|event)\n" 330 " Select how attached port is retrieved for setup.\n\n" 331 332 "set tx loopback (port_id) (on|off)\n" 333 " Enable or disable tx loopback.\n\n" 334 335 "set all queues drop (port_id) (on|off)\n" 336 " Set drop enable bit for all queues.\n\n" 337 338 "set vf split drop (port_id) (vf_id) (on|off)\n" 339 " Set split drop enable bit for a VF from the PF.\n\n" 340 341 "set vf mac antispoof (port_id) (vf_id) (on|off).\n" 342 " Set MAC antispoof for a VF from the PF.\n\n" 343 344 "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n" 345 " Enable MACsec offload.\n\n" 346 347 "set macsec offload (port_id) off\n" 348 " Disable MACsec offload.\n\n" 349 350 "set macsec sc (tx|rx) (port_id) (mac) (pi)\n" 351 " Configure MACsec secure connection (SC).\n\n" 352 353 "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n" 354 " Configure MACsec secure association (SA).\n\n" 355 356 "vlan set stripq (on|off) (port_id,queue_id)\n" 357 " Set the VLAN strip for a queue on a port.\n\n" 358 359 "set vf vlan stripq (port_id) (vf_id) (on|off)\n" 360 " Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n" 361 362 "set vf vlan insert (port_id) (vf_id) (vlan_id)\n" 363 " Set VLAN insert for a VF from the PF.\n\n" 364 365 "set vf vlan antispoof (port_id) (vf_id) (on|off)\n" 366 " Set VLAN antispoof for a VF from the PF.\n\n" 367 368 "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n" 369 " Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n" 370 371 "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n" 372 " Set the VLAN strip or filter or qinq strip or extend\n\n" 373 374 "vlan set (inner|outer) tpid (value) (port_id)\n" 375 " Set the VLAN TPID for Packet Filtering on" 376 " a port\n\n" 377 378 "rx_vlan add (vlan_id|all) (port_id)\n" 379 " Add a vlan_id, or all identifiers, to the set" 380 " of VLAN identifiers filtered by port_id.\n\n" 381 382 "rx_vlan rm (vlan_id|all) (port_id)\n" 383 " Remove a vlan_id, or all identifiers, from the set" 384 " of VLAN identifiers filtered by port_id.\n\n" 385 386 "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n" 387 " Add a vlan_id, to the set of VLAN identifiers" 388 "filtered for VF(s) from port_id.\n\n" 389 390 "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n" 391 " Remove a vlan_id, to the set of VLAN identifiers" 392 "filtered for VF(s) from port_id.\n\n" 393 394 "rx_vxlan_port add (udp_port) (port_id)\n" 395 " Add an UDP port for VXLAN packet filter on a port\n\n" 396 397 "rx_vxlan_port rm (udp_port) (port_id)\n" 398 " Remove an UDP port for VXLAN packet filter on a port\n\n" 399 400 "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n" 401 " Set hardware insertion of VLAN IDs (single or double VLAN " 402 "depends on the number of VLAN IDs) in packets sent on a port.\n\n" 403 404 "tx_vlan set pvid port_id vlan_id (on|off)\n" 405 " Set port based TX VLAN insertion.\n\n" 406 407 "tx_vlan reset (port_id)\n" 408 " Disable hardware insertion of a VLAN header in" 409 " packets sent on a port.\n\n" 410 411 "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n" 412 " Select hardware or software calculation of the" 413 " checksum when transmitting a packet using the" 414 " csum forward engine.\n" 415 " ip|udp|tcp|sctp always concern the inner layer.\n" 416 " outer-ip concerns the outer IP layer in" 417 " outer-udp concerns the outer UDP layer in" 418 " case the packet is recognized as a tunnel packet by" 419 " the forward engine (vxlan, gre and ipip are supported)\n" 420 " Please check the NIC datasheet for HW limits.\n\n" 421 422 "csum parse-tunnel (on|off) (tx_port_id)\n" 423 " If disabled, treat tunnel packets as non-tunneled" 424 " packets (treat inner headers as payload). The port\n" 425 " argument is the port used for TX in csum forward" 426 " engine.\n\n" 427 428 "csum show (port_id)\n" 429 " Display tx checksum offload configuration\n\n" 430 431 "tso set (segsize) (portid)\n" 432 " Enable TCP Segmentation Offload in csum forward" 433 " engine.\n" 434 " Please check the NIC datasheet for HW limits.\n\n" 435 436 "tso show (portid)" 437 " Display the status of TCP Segmentation Offload.\n\n" 438 439 #ifdef RTE_LIB_GRO 440 "set port (port_id) gro on|off\n" 441 " Enable or disable Generic Receive Offload in" 442 " csum forwarding engine.\n\n" 443 444 "show port (port_id) gro\n" 445 " Display GRO configuration.\n\n" 446 447 "set gro flush (cycles)\n" 448 " Set the cycle to flush GROed packets from" 449 " reassembly tables.\n\n" 450 #endif 451 452 #ifdef RTE_LIB_GSO 453 "set port (port_id) gso (on|off)" 454 " Enable or disable Generic Segmentation Offload in" 455 " csum forwarding engine.\n\n" 456 457 "set gso segsz (length)\n" 458 " Set max packet length for output GSO segments," 459 " including packet header and payload.\n\n" 460 461 "show port (port_id) gso\n" 462 " Show GSO configuration.\n\n" 463 #endif 464 465 "set fwd (%s)\n" 466 " Set packet forwarding mode.\n\n" 467 468 "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n" 469 " Add a MAC address on port_id.\n\n" 470 471 "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n" 472 " Remove a MAC address from port_id.\n\n" 473 474 "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n" 475 " Set the default MAC address for port_id.\n\n" 476 477 "mac_addr add port (port_id) vf (vf_id) (mac_address)\n" 478 " Add a MAC address for a VF on the port.\n\n" 479 480 "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n" 481 " Set the MAC address for a VF from the PF.\n\n" 482 483 "set eth-peer (port_id) (peer_addr)\n" 484 " set the peer address for certain port.\n\n" 485 486 "set port (port_id) uta (mac_address|all) (on|off)\n" 487 " Add/Remove a or all unicast hash filter(s)" 488 "from port X.\n\n" 489 490 "set promisc (port_id|all) (on|off)\n" 491 " Set the promiscuous mode on port_id, or all.\n\n" 492 493 "set allmulti (port_id|all) (on|off)\n" 494 " Set the allmulti mode on port_id, or all.\n\n" 495 496 "set flow_ctrl rx (on|off) tx (on|off) (high_water)" 497 " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd" 498 " (on|off) autoneg (on|off) (port_id)\n" 499 "set flow_ctrl rx (on|off) (portid)\n" 500 "set flow_ctrl tx (on|off) (portid)\n" 501 "set flow_ctrl high_water (high_water) (portid)\n" 502 "set flow_ctrl low_water (low_water) (portid)\n" 503 "set flow_ctrl pause_time (pause_time) (portid)\n" 504 "set flow_ctrl send_xon (send_xon) (portid)\n" 505 "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n" 506 "set flow_ctrl autoneg (on|off) (port_id)\n" 507 " Set the link flow control parameter on a port.\n\n" 508 509 "set pfc_ctrl rx (on|off) tx (on|off) (high_water)" 510 " (low_water) (pause_time) (priority) (port_id)\n" 511 " Set the priority flow control parameter on a" 512 " port.\n\n" 513 514 "set pfc_queue_ctrl (port_id) rx (on|off) (tx_qid)" 515 " (tx_tc) tx (on|off) (rx_qid) (rx_tc) (pause_time)\n" 516 " Set the queue priority flow control parameter on a" 517 " given Rx and Tx queues of a port.\n\n" 518 519 "set port (port_id) rxq (queue_id) avail_thresh (0..99)>\n " 520 " set available descriptors threshold for Rx queue\n\n" 521 522 "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n" 523 " Set statistics mapping (qmapping 0..15) for RX/TX" 524 " queue on port.\n" 525 " e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2" 526 " on port 0 to mapping 5.\n\n" 527 528 "set xstats-hide-zero on|off\n" 529 " Set the option to hide the zero values" 530 " for xstats display.\n" 531 532 "set record-core-cycles on|off\n" 533 " Set the option to enable measurement of CPU cycles.\n" 534 535 "set record-burst-stats on|off\n" 536 " Set the option to enable display of RX and TX bursts.\n" 537 538 "set port (port_id) vf (vf_id) rx|tx on|off\n" 539 " Enable/Disable a VF receive/transmit from a port\n\n" 540 541 "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM" 542 "|MPE) (on|off)\n" 543 " AUPE:accepts untagged VLAN;" 544 "ROPE:accept unicast hash\n\n" 545 " BAM:accepts broadcast packets;" 546 "MPE:accepts all multicast packets\n\n" 547 " Enable/Disable a VF receive mode of a port\n\n" 548 549 "set port (port_id) queue (queue_id) rate (rate_num)\n" 550 " Set rate limit for a queue of a port\n\n" 551 552 "set port (port_id) vf (vf_id) rate (rate_num) " 553 "queue_mask (queue_mask_value)\n" 554 " Set rate limit for queues in VF of a port\n\n" 555 556 "set flush_rx (on|off)\n" 557 " Flush (default) or don't flush RX streams before" 558 " forwarding. Mainly used with PCAP drivers.\n\n" 559 560 "set bypass mode (normal|bypass|isolate) (port_id)\n" 561 " Set the bypass mode for the lowest port on bypass enabled" 562 " NIC.\n\n" 563 564 "set bypass event (timeout|os_on|os_off|power_on|power_off) " 565 "mode (normal|bypass|isolate) (port_id)\n" 566 " Set the event required to initiate specified bypass mode for" 567 " the lowest port on a bypass enabled NIC where:\n" 568 " timeout = enable bypass after watchdog timeout.\n" 569 " os_on = enable bypass when OS/board is powered on.\n" 570 " os_off = enable bypass when OS/board is powered off.\n" 571 " power_on = enable bypass when power supply is turned on.\n" 572 " power_off = enable bypass when power supply is turned off." 573 "\n\n" 574 575 "set bypass timeout (0|1.5|2|3|4|8|16|32)\n" 576 " Set the bypass watchdog timeout to 'n' seconds" 577 " where 0 = instant.\n\n" 578 579 "show bypass config (port_id)\n" 580 " Show the bypass configuration for a bypass enabled NIC" 581 " using the lowest port on the NIC.\n\n" 582 583 "set link-up port (port_id)\n" 584 " Set link up for a port.\n\n" 585 586 "set link-down port (port_id)\n" 587 " Set link down for a port.\n\n" 588 589 "set port (port_id) ptype_mask (ptype_mask)\n" 590 " set packet types classification for a specific port\n\n" 591 592 "show port meter cap (port_id)\n" 593 " Show port meter capability information\n\n" 594 595 "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs) (packet_mode)\n" 596 " meter profile add - srtcm rfc 2697\n\n" 597 598 "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs) (packet_mode)\n" 599 " meter profile add - trtcm rfc 2698\n\n" 600 601 "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs) (packet_mode)\n" 602 " meter profile add - trtcm rfc 4115\n\n" 603 604 "del port meter profile (port_id) (profile_id)\n" 605 " meter profile delete\n\n" 606 607 "create port meter (port_id) (mtr_id) (profile_id) (policy_id) (meter_enable)\n" 608 "(stats_mask) (shared) (use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n" 609 "(dscp_tbl_entry63)]\n" 610 " meter create\n\n" 611 612 "enable port meter (port_id) (mtr_id)\n" 613 " meter enable\n\n" 614 615 "disable port meter (port_id) (mtr_id)\n" 616 " meter disable\n\n" 617 618 "del port meter (port_id) (mtr_id)\n" 619 " meter delete\n\n" 620 621 "add port meter policy (port_id) (policy_id) g_actions (actions)\n" 622 "y_actions (actions) r_actions (actions)\n" 623 " meter policy add\n\n" 624 625 "del port meter policy (port_id) (policy_id)\n" 626 " meter policy delete\n\n" 627 628 "set port meter profile (port_id) (mtr_id) (profile_id)\n" 629 " meter update meter profile\n\n" 630 631 "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n" 632 "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n" 633 " update meter dscp table entries\n\n" 634 635 "set port meter policer action (port_id) (mtr_id) (action_mask)\n" 636 "(action0) [(action1) (action2)]\n" 637 " meter update policer action\n\n" 638 639 "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n" 640 " meter update stats\n\n" 641 642 "set port (port_id) fec_mode auto|off|rs|baser\n" 643 " set fec mode for a specific port\n\n" 644 645 , list_pkt_forwarding_modes() 646 ); 647 } 648 649 if (show_all || !strcmp(res->section, "ports")) { 650 651 cmdline_printf( 652 cl, 653 "\n" 654 "Port Operations:\n" 655 "----------------\n\n" 656 657 "port start (port_id|all)\n" 658 " Start all ports or port_id.\n\n" 659 660 "port stop (port_id|all)\n" 661 " Stop all ports or port_id.\n\n" 662 663 "port close (port_id|all)\n" 664 " Close all ports or port_id.\n\n" 665 666 "port reset (port_id|all)\n" 667 " Reset all ports or port_id.\n\n" 668 669 "port attach (ident)\n" 670 " Attach physical or virtual dev by pci address or virtual device name\n\n" 671 672 "port detach (port_id)\n" 673 " Detach physical or virtual dev by port_id\n\n" 674 675 "port config (port_id|all)" 676 " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)" 677 " duplex (half|full|auto)\n" 678 " Set speed and duplex for all ports or port_id\n\n" 679 680 "port config (port_id|all) loopback (mode)\n" 681 " Set loopback mode for all ports or port_id\n\n" 682 683 "port config all (rxq|txq|rxd|txd) (value)\n" 684 " Set number for rxq/txq/rxd/txd.\n\n" 685 686 "port config all max-pkt-len (value)\n" 687 " Set the max packet length.\n\n" 688 689 "port config all max-lro-pkt-size (value)\n" 690 " Set the max LRO aggregated packet size.\n\n" 691 692 "port config all drop-en (on|off)\n" 693 " Enable or disable packet drop on all RX queues of all ports when no " 694 "receive buffers available.\n\n" 695 696 "port config all rss (all|default|ip|tcp|udp|sctp|" 697 "ether|port|vxlan|geneve|nvgre|vxlan-gpe|ecpri|mpls|ipv4-chksum|l2tpv2|" 698 "none|level-default|level-outer|level-inner|<flowtype_id>)\n" 699 " Set the RSS mode.\n\n" 700 701 "port config port-id rss reta (hash,queue)[,(hash,queue)]\n" 702 " Set the RSS redirection table.\n\n" 703 704 "port config (port_id) dcb vt (on|off) (traffic_class)" 705 " pfc (on|off)\n" 706 " Set the DCB mode.\n\n" 707 708 "port config all burst (value)\n" 709 " Set the number of packets per burst.\n\n" 710 711 "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)" 712 " (value)\n" 713 " Set the ring prefetch/host/writeback threshold" 714 " for tx/rx queue.\n\n" 715 716 "port config all (txfreet|txrst|rxfreet) (value)\n" 717 " Set free threshold for rx/tx, or set" 718 " tx rs bit threshold.\n\n" 719 "port config mtu X value\n" 720 " Set the MTU of port X to a given value\n\n" 721 722 "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n" 723 " Set a rx/tx queue's ring size configuration, the new" 724 " value will take effect after command that (re-)start the port" 725 " or command that setup the specific queue\n\n" 726 727 "port (port_id) (rxq|txq) (queue_id) (start|stop)\n" 728 " Start/stop a rx/tx queue of port X. Only take effect" 729 " when port X is started\n\n" 730 731 "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n" 732 " Switch on/off a deferred start of port X rx/tx queue. Only" 733 " take effect when port X is stopped.\n\n" 734 735 "port (port_id) (rxq|txq) (queue_id) setup\n" 736 " Setup a rx/tx queue of port X.\n\n" 737 738 "port config (port_id) udp_tunnel_port add|rm vxlan|geneve|ecpri (udp_port)\n\n" 739 " Add/remove UDP tunnel port for tunneling offload\n\n" 740 741 "port config <port_id> rx_offload vlan_strip|" 742 "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|" 743 "outer_ipv4_cksum|macsec_strip|header_split|" 744 "vlan_filter|vlan_extend|jumbo_frame|scatter|" 745 "buffer_split|timestamp|security|keep_crc on|off\n" 746 " Enable or disable a per port Rx offloading" 747 " on all Rx queues of a port\n\n" 748 749 "port (port_id) rxq (queue_id) rx_offload vlan_strip|" 750 "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|" 751 "outer_ipv4_cksum|macsec_strip|header_split|" 752 "vlan_filter|vlan_extend|jumbo_frame|scatter|" 753 "buffer_split|timestamp|security|keep_crc on|off\n" 754 " Enable or disable a per queue Rx offloading" 755 " only on a specific Rx queue\n\n" 756 757 "port config (port_id) tx_offload vlan_insert|" 758 "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|" 759 "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|" 760 "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|" 761 "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|" 762 "security on|off\n" 763 " Enable or disable a per port Tx offloading" 764 " on all Tx queues of a port\n\n" 765 766 "port (port_id) txq (queue_id) tx_offload vlan_insert|" 767 "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|" 768 "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|" 769 "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert" 770 "|mt_lockfree|multi_segs|mbuf_fast_free|security" 771 " on|off\n" 772 " Enable or disable a per queue Tx offloading" 773 " only on a specific Tx queue\n\n" 774 775 "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n" 776 " Load an eBPF program as a callback" 777 " for particular RX/TX queue\n\n" 778 779 "bpf-unload rx|tx (port) (queue)\n" 780 " Unload previously loaded eBPF program" 781 " for particular RX/TX queue\n\n" 782 783 "port config (port_id) tx_metadata (value)\n" 784 " Set Tx metadata value per port. Testpmd will add this value" 785 " to any Tx packet sent from this port\n\n" 786 787 "port config (port_id) dynf (name) set|clear\n" 788 " Register a dynf and Set/clear this flag on Tx. " 789 "Testpmd will set this value to any Tx packet " 790 "sent from this port\n\n" 791 792 "port cleanup (port_id) txq (queue_id) (free_cnt)\n" 793 " Cleanup txq mbufs for a specific Tx queue\n\n" 794 ); 795 } 796 797 if (show_all || !strcmp(res->section, "registers")) { 798 799 cmdline_printf( 800 cl, 801 "\n" 802 "Registers:\n" 803 "----------\n\n" 804 805 "read reg (port_id) (address)\n" 806 " Display value of a port register.\n\n" 807 808 "read regfield (port_id) (address) (bit_x) (bit_y)\n" 809 " Display a port register bit field.\n\n" 810 811 "read regbit (port_id) (address) (bit_x)\n" 812 " Display a single port register bit.\n\n" 813 814 "write reg (port_id) (address) (value)\n" 815 " Set value of a port register.\n\n" 816 817 "write regfield (port_id) (address) (bit_x) (bit_y)" 818 " (value)\n" 819 " Set bit field of a port register.\n\n" 820 821 "write regbit (port_id) (address) (bit_x) (value)\n" 822 " Set single bit value of a port register.\n\n" 823 ); 824 } 825 if (show_all || !strcmp(res->section, "filters")) { 826 827 cmdline_printf( 828 cl, 829 "\n" 830 "filters:\n" 831 "--------\n\n" 832 833 "flow_director_mask (port_id) mode IP vlan (vlan_value)" 834 " src_mask (ipv4_src) (ipv6_src) (src_port)" 835 " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n" 836 " Set flow director IP mask.\n\n" 837 838 "flow_director_mask (port_id) mode MAC-VLAN" 839 " vlan (vlan_value)\n" 840 " Set flow director MAC-VLAN mask.\n\n" 841 842 "flow_director_mask (port_id) mode Tunnel" 843 " vlan (vlan_value) mac (mac_value)" 844 " tunnel-type (tunnel_type_value)" 845 " tunnel-id (tunnel_id_value)\n" 846 " Set flow director Tunnel mask.\n\n" 847 848 "flow_director_flex_payload (port_id)" 849 " (raw|l2|l3|l4) (config)\n" 850 " Configure flex payload selection.\n\n" 851 852 "flow validate {port_id}" 853 " [group {group_id}] [priority {level}]" 854 " [ingress] [egress]" 855 " pattern {item} [/ {item} [...]] / end" 856 " actions {action} [/ {action} [...]] / end\n" 857 " Check whether a flow rule can be created.\n\n" 858 859 "flow create {port_id}" 860 " [group {group_id}] [priority {level}]" 861 " [ingress] [egress]" 862 " pattern {item} [/ {item} [...]] / end" 863 " actions {action} [/ {action} [...]] / end\n" 864 " Create a flow rule.\n\n" 865 866 "flow destroy {port_id} rule {rule_id} [...]\n" 867 " Destroy specific flow rules.\n\n" 868 869 "flow flush {port_id}\n" 870 " Destroy all flow rules.\n\n" 871 872 "flow query {port_id} {rule_id} {action}\n" 873 " Query an existing flow rule.\n\n" 874 875 "flow list {port_id} [group {group_id}] [...]\n" 876 " List existing flow rules sorted by priority," 877 " filtered by group identifiers.\n\n" 878 879 "flow isolate {port_id} {boolean}\n" 880 " Restrict ingress traffic to the defined" 881 " flow rules\n\n" 882 883 "flow aged {port_id} [destroy]\n" 884 " List and destroy aged flows" 885 " flow rules\n\n" 886 887 "flow indirect_action {port_id} create" 888 " [action_id {indirect_action_id}]" 889 " [ingress] [egress]" 890 " action {action} / end\n" 891 " Create indirect action.\n\n" 892 893 "flow indirect_action {port_id} update" 894 " {indirect_action_id} action {action} / end\n" 895 " Update indirect action.\n\n" 896 897 "flow indirect_action {port_id} destroy" 898 " action_id {indirect_action_id} [...]\n" 899 " Destroy specific indirect actions.\n\n" 900 901 "flow indirect_action {port_id} query" 902 " {indirect_action_id}\n" 903 " Query an existing indirect action.\n\n" 904 905 "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src" 906 " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst" 907 " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n" 908 " Configure the VXLAN encapsulation for flows.\n\n" 909 910 "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)" 911 " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)" 912 " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)" 913 " eth-dst (eth-dst)\n" 914 " Configure the VXLAN encapsulation for flows.\n\n" 915 916 "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src" 917 " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)" 918 " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)" 919 " eth-dst (eth-dst)\n" 920 " Configure the VXLAN encapsulation for flows.\n\n" 921 922 "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src" 923 " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst" 924 " (eth-dst)\n" 925 " Configure the NVGRE encapsulation for flows.\n\n" 926 927 "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)" 928 " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)" 929 " eth-src (eth-src) eth-dst (eth-dst)\n" 930 " Configure the NVGRE encapsulation for flows.\n\n" 931 932 "set raw_encap {flow items}\n" 933 " Configure the encapsulation with raw data.\n\n" 934 935 "set raw_decap {flow items}\n" 936 " Configure the decapsulation with raw data.\n\n" 937 938 ); 939 } 940 941 if (show_all || !strcmp(res->section, "traffic_management")) { 942 cmdline_printf( 943 cl, 944 "\n" 945 "Traffic Management:\n" 946 "--------------\n" 947 "show port tm cap (port_id)\n" 948 " Display the port TM capability.\n\n" 949 950 "show port tm level cap (port_id) (level_id)\n" 951 " Display the port TM hierarchical level capability.\n\n" 952 953 "show port tm node cap (port_id) (node_id)\n" 954 " Display the port TM node capability.\n\n" 955 956 "show port tm node type (port_id) (node_id)\n" 957 " Display the port TM node type.\n\n" 958 959 "show port tm node stats (port_id) (node_id) (clear)\n" 960 " Display the port TM node stats.\n\n" 961 962 "add port tm node shaper profile (port_id) (shaper_profile_id)" 963 " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)" 964 " (packet_length_adjust) (packet_mode)\n" 965 " Add port tm node private shaper profile.\n\n" 966 967 "del port tm node shaper profile (port_id) (shaper_profile_id)\n" 968 " Delete port tm node private shaper profile.\n\n" 969 970 "add port tm node shared shaper (port_id) (shared_shaper_id)" 971 " (shaper_profile_id)\n" 972 " Add/update port tm node shared shaper.\n\n" 973 974 "del port tm node shared shaper (port_id) (shared_shaper_id)\n" 975 " Delete port tm node shared shaper.\n\n" 976 977 "set port tm node shaper profile (port_id) (node_id)" 978 " (shaper_profile_id)\n" 979 " Set port tm node shaper profile.\n\n" 980 981 "add port tm node wred profile (port_id) (wred_profile_id)" 982 " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)" 983 " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)" 984 " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n" 985 " Add port tm node wred profile.\n\n" 986 987 "del port tm node wred profile (port_id) (wred_profile_id)\n" 988 " Delete port tm node wred profile.\n\n" 989 990 "add port tm nonleaf node (port_id) (node_id) (parent_node_id)" 991 " (priority) (weight) (level_id) (shaper_profile_id)" 992 " (n_sp_priorities) (stats_mask) (n_shared_shapers)" 993 " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n" 994 " Add port tm nonleaf node.\n\n" 995 996 "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)" 997 " (priority) (weight) (level_id) (shaper_profile_id)" 998 " (n_sp_priorities) (stats_mask) (n_shared_shapers)" 999 " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n" 1000 " Add port tm nonleaf node with pkt mode enabled.\n\n" 1001 1002 "add port tm leaf node (port_id) (node_id) (parent_node_id)" 1003 " (priority) (weight) (level_id) (shaper_profile_id)" 1004 " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)" 1005 " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n" 1006 " Add port tm leaf node.\n\n" 1007 1008 "del port tm node (port_id) (node_id)\n" 1009 " Delete port tm node.\n\n" 1010 1011 "set port tm node parent (port_id) (node_id) (parent_node_id)" 1012 " (priority) (weight)\n" 1013 " Set port tm node parent.\n\n" 1014 1015 "suspend port tm node (port_id) (node_id)" 1016 " Suspend tm node.\n\n" 1017 1018 "resume port tm node (port_id) (node_id)" 1019 " Resume tm node.\n\n" 1020 1021 "port tm hierarchy commit (port_id) (clean_on_fail)\n" 1022 " Commit tm hierarchy.\n\n" 1023 1024 "set port tm mark ip_ecn (port) (green) (yellow)" 1025 " (red)\n" 1026 " Enables/Disables the traffic management marking" 1027 " for IP ECN (Explicit Congestion Notification)" 1028 " packets on a given port\n\n" 1029 1030 "set port tm mark ip_dscp (port) (green) (yellow)" 1031 " (red)\n" 1032 " Enables/Disables the traffic management marking" 1033 " on the port for IP dscp packets\n\n" 1034 1035 "set port tm mark vlan_dei (port) (green) (yellow)" 1036 " (red)\n" 1037 " Enables/Disables the traffic management marking" 1038 " on the port for VLAN packets with DEI enabled\n\n" 1039 ); 1040 } 1041 1042 if (show_all || !strcmp(res->section, "devices")) { 1043 cmdline_printf( 1044 cl, 1045 "\n" 1046 "Device Operations:\n" 1047 "--------------\n" 1048 "device detach (identifier)\n" 1049 " Detach device by identifier.\n\n" 1050 ); 1051 } 1052 1053 if (show_all || !strcmp(res->section, "drivers")) { 1054 struct testpmd_driver_commands *c; 1055 unsigned int i; 1056 1057 cmdline_printf( 1058 cl, 1059 "\n" 1060 "Driver specific:\n" 1061 "----------------\n" 1062 ); 1063 TAILQ_FOREACH(c, &driver_commands_head, next) { 1064 for (i = 0; c->commands[i].ctx != NULL; i++) 1065 cmdline_printf(cl, "%s\n", c->commands[i].help); 1066 } 1067 } 1068 } 1069 1070 static cmdline_parse_token_string_t cmd_help_long_help = 1071 TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help"); 1072 1073 static cmdline_parse_token_string_t cmd_help_long_section = 1074 TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section, 1075 "all#control#display#config#ports#registers#" 1076 "filters#traffic_management#devices#drivers"); 1077 1078 static cmdline_parse_inst_t cmd_help_long = { 1079 .f = cmd_help_long_parsed, 1080 .data = NULL, 1081 .help_str = "help all|control|display|config|ports|register|" 1082 "filters|traffic_management|devices|drivers: " 1083 "Show help", 1084 .tokens = { 1085 (void *)&cmd_help_long_help, 1086 (void *)&cmd_help_long_section, 1087 NULL, 1088 }, 1089 }; 1090 1091 1092 /* *** start/stop/close all ports *** */ 1093 struct cmd_operate_port_result { 1094 cmdline_fixed_string_t keyword; 1095 cmdline_fixed_string_t name; 1096 cmdline_fixed_string_t value; 1097 }; 1098 1099 static void cmd_operate_port_parsed(void *parsed_result, 1100 __rte_unused struct cmdline *cl, 1101 __rte_unused void *data) 1102 { 1103 struct cmd_operate_port_result *res = parsed_result; 1104 1105 if (!strcmp(res->name, "start")) 1106 start_port(RTE_PORT_ALL); 1107 else if (!strcmp(res->name, "stop")) 1108 stop_port(RTE_PORT_ALL); 1109 else if (!strcmp(res->name, "close")) 1110 close_port(RTE_PORT_ALL); 1111 else if (!strcmp(res->name, "reset")) 1112 reset_port(RTE_PORT_ALL); 1113 else 1114 fprintf(stderr, "Unknown parameter\n"); 1115 } 1116 1117 static cmdline_parse_token_string_t cmd_operate_port_all_cmd = 1118 TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword, 1119 "port"); 1120 static cmdline_parse_token_string_t cmd_operate_port_all_port = 1121 TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name, 1122 "start#stop#close#reset"); 1123 static cmdline_parse_token_string_t cmd_operate_port_all_all = 1124 TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all"); 1125 1126 static cmdline_parse_inst_t cmd_operate_port = { 1127 .f = cmd_operate_port_parsed, 1128 .data = NULL, 1129 .help_str = "port start|stop|close|reset all: Start/Stop/Close/Reset all ports", 1130 .tokens = { 1131 (void *)&cmd_operate_port_all_cmd, 1132 (void *)&cmd_operate_port_all_port, 1133 (void *)&cmd_operate_port_all_all, 1134 NULL, 1135 }, 1136 }; 1137 1138 /* *** start/stop/close specific port *** */ 1139 struct cmd_operate_specific_port_result { 1140 cmdline_fixed_string_t keyword; 1141 cmdline_fixed_string_t name; 1142 uint8_t value; 1143 }; 1144 1145 static void cmd_operate_specific_port_parsed(void *parsed_result, 1146 __rte_unused struct cmdline *cl, 1147 __rte_unused void *data) 1148 { 1149 struct cmd_operate_specific_port_result *res = parsed_result; 1150 1151 if (!strcmp(res->name, "start")) 1152 start_port(res->value); 1153 else if (!strcmp(res->name, "stop")) 1154 stop_port(res->value); 1155 else if (!strcmp(res->name, "close")) 1156 close_port(res->value); 1157 else if (!strcmp(res->name, "reset")) 1158 reset_port(res->value); 1159 else 1160 fprintf(stderr, "Unknown parameter\n"); 1161 } 1162 1163 static cmdline_parse_token_string_t cmd_operate_specific_port_cmd = 1164 TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result, 1165 keyword, "port"); 1166 static cmdline_parse_token_string_t cmd_operate_specific_port_port = 1167 TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result, 1168 name, "start#stop#close#reset"); 1169 static cmdline_parse_token_num_t cmd_operate_specific_port_id = 1170 TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result, 1171 value, RTE_UINT8); 1172 1173 static cmdline_parse_inst_t cmd_operate_specific_port = { 1174 .f = cmd_operate_specific_port_parsed, 1175 .data = NULL, 1176 .help_str = "port start|stop|close|reset <port_id>: Start/Stop/Close/Reset port_id", 1177 .tokens = { 1178 (void *)&cmd_operate_specific_port_cmd, 1179 (void *)&cmd_operate_specific_port_port, 1180 (void *)&cmd_operate_specific_port_id, 1181 NULL, 1182 }, 1183 }; 1184 1185 /* *** enable port setup (after attach) via iterator or event *** */ 1186 struct cmd_set_port_setup_on_result { 1187 cmdline_fixed_string_t set; 1188 cmdline_fixed_string_t port; 1189 cmdline_fixed_string_t setup; 1190 cmdline_fixed_string_t on; 1191 cmdline_fixed_string_t mode; 1192 }; 1193 1194 static void cmd_set_port_setup_on_parsed(void *parsed_result, 1195 __rte_unused struct cmdline *cl, 1196 __rte_unused void *data) 1197 { 1198 struct cmd_set_port_setup_on_result *res = parsed_result; 1199 1200 if (strcmp(res->mode, "event") == 0) 1201 setup_on_probe_event = true; 1202 else if (strcmp(res->mode, "iterator") == 0) 1203 setup_on_probe_event = false; 1204 else 1205 fprintf(stderr, "Unknown mode\n"); 1206 } 1207 1208 static cmdline_parse_token_string_t cmd_set_port_setup_on_set = 1209 TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result, 1210 set, "set"); 1211 static cmdline_parse_token_string_t cmd_set_port_setup_on_port = 1212 TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result, 1213 port, "port"); 1214 static cmdline_parse_token_string_t cmd_set_port_setup_on_setup = 1215 TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result, 1216 setup, "setup"); 1217 static cmdline_parse_token_string_t cmd_set_port_setup_on_on = 1218 TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result, 1219 on, "on"); 1220 static cmdline_parse_token_string_t cmd_set_port_setup_on_mode = 1221 TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result, 1222 mode, "iterator#event"); 1223 1224 static cmdline_parse_inst_t cmd_set_port_setup_on = { 1225 .f = cmd_set_port_setup_on_parsed, 1226 .data = NULL, 1227 .help_str = "set port setup on iterator|event", 1228 .tokens = { 1229 (void *)&cmd_set_port_setup_on_set, 1230 (void *)&cmd_set_port_setup_on_port, 1231 (void *)&cmd_set_port_setup_on_setup, 1232 (void *)&cmd_set_port_setup_on_on, 1233 (void *)&cmd_set_port_setup_on_mode, 1234 NULL, 1235 }, 1236 }; 1237 1238 /* *** attach a specified port *** */ 1239 struct cmd_operate_attach_port_result { 1240 cmdline_fixed_string_t port; 1241 cmdline_fixed_string_t keyword; 1242 cmdline_multi_string_t identifier; 1243 }; 1244 1245 static void cmd_operate_attach_port_parsed(void *parsed_result, 1246 __rte_unused struct cmdline *cl, 1247 __rte_unused void *data) 1248 { 1249 struct cmd_operate_attach_port_result *res = parsed_result; 1250 1251 if (!strcmp(res->keyword, "attach")) 1252 attach_port(res->identifier); 1253 else 1254 fprintf(stderr, "Unknown parameter\n"); 1255 } 1256 1257 static cmdline_parse_token_string_t cmd_operate_attach_port_port = 1258 TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result, 1259 port, "port"); 1260 static cmdline_parse_token_string_t cmd_operate_attach_port_keyword = 1261 TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result, 1262 keyword, "attach"); 1263 static cmdline_parse_token_string_t cmd_operate_attach_port_identifier = 1264 TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result, 1265 identifier, TOKEN_STRING_MULTI); 1266 1267 static cmdline_parse_inst_t cmd_operate_attach_port = { 1268 .f = cmd_operate_attach_port_parsed, 1269 .data = NULL, 1270 .help_str = "port attach <identifier>: " 1271 "(identifier: pci address or virtual dev name)", 1272 .tokens = { 1273 (void *)&cmd_operate_attach_port_port, 1274 (void *)&cmd_operate_attach_port_keyword, 1275 (void *)&cmd_operate_attach_port_identifier, 1276 NULL, 1277 }, 1278 }; 1279 1280 /* *** detach a specified port *** */ 1281 struct cmd_operate_detach_port_result { 1282 cmdline_fixed_string_t port; 1283 cmdline_fixed_string_t keyword; 1284 portid_t port_id; 1285 }; 1286 1287 static void cmd_operate_detach_port_parsed(void *parsed_result, 1288 __rte_unused struct cmdline *cl, 1289 __rte_unused void *data) 1290 { 1291 struct cmd_operate_detach_port_result *res = parsed_result; 1292 1293 if (!strcmp(res->keyword, "detach")) { 1294 RTE_ETH_VALID_PORTID_OR_RET(res->port_id); 1295 detach_port_device(res->port_id); 1296 } else { 1297 fprintf(stderr, "Unknown parameter\n"); 1298 } 1299 } 1300 1301 static cmdline_parse_token_string_t cmd_operate_detach_port_port = 1302 TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result, 1303 port, "port"); 1304 static cmdline_parse_token_string_t cmd_operate_detach_port_keyword = 1305 TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result, 1306 keyword, "detach"); 1307 static cmdline_parse_token_num_t cmd_operate_detach_port_port_id = 1308 TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result, 1309 port_id, RTE_UINT16); 1310 1311 static cmdline_parse_inst_t cmd_operate_detach_port = { 1312 .f = cmd_operate_detach_port_parsed, 1313 .data = NULL, 1314 .help_str = "port detach <port_id>", 1315 .tokens = { 1316 (void *)&cmd_operate_detach_port_port, 1317 (void *)&cmd_operate_detach_port_keyword, 1318 (void *)&cmd_operate_detach_port_port_id, 1319 NULL, 1320 }, 1321 }; 1322 1323 /* *** detach device by identifier *** */ 1324 struct cmd_operate_detach_device_result { 1325 cmdline_fixed_string_t device; 1326 cmdline_fixed_string_t keyword; 1327 cmdline_fixed_string_t identifier; 1328 }; 1329 1330 static void cmd_operate_detach_device_parsed(void *parsed_result, 1331 __rte_unused struct cmdline *cl, 1332 __rte_unused void *data) 1333 { 1334 struct cmd_operate_detach_device_result *res = parsed_result; 1335 1336 if (!strcmp(res->keyword, "detach")) 1337 detach_devargs(res->identifier); 1338 else 1339 fprintf(stderr, "Unknown parameter\n"); 1340 } 1341 1342 static cmdline_parse_token_string_t cmd_operate_detach_device_device = 1343 TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result, 1344 device, "device"); 1345 static cmdline_parse_token_string_t cmd_operate_detach_device_keyword = 1346 TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result, 1347 keyword, "detach"); 1348 static cmdline_parse_token_string_t cmd_operate_detach_device_identifier = 1349 TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result, 1350 identifier, NULL); 1351 1352 static cmdline_parse_inst_t cmd_operate_detach_device = { 1353 .f = cmd_operate_detach_device_parsed, 1354 .data = NULL, 1355 .help_str = "device detach <identifier>:" 1356 "(identifier: pci address or virtual dev name)", 1357 .tokens = { 1358 (void *)&cmd_operate_detach_device_device, 1359 (void *)&cmd_operate_detach_device_keyword, 1360 (void *)&cmd_operate_detach_device_identifier, 1361 NULL, 1362 }, 1363 }; 1364 /* *** configure speed for all ports *** */ 1365 struct cmd_config_speed_all { 1366 cmdline_fixed_string_t port; 1367 cmdline_fixed_string_t keyword; 1368 cmdline_fixed_string_t all; 1369 cmdline_fixed_string_t item1; 1370 cmdline_fixed_string_t item2; 1371 cmdline_fixed_string_t value1; 1372 cmdline_fixed_string_t value2; 1373 }; 1374 1375 static int 1376 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed) 1377 { 1378 1379 int duplex; 1380 1381 if (!strcmp(duplexstr, "half")) { 1382 duplex = RTE_ETH_LINK_HALF_DUPLEX; 1383 } else if (!strcmp(duplexstr, "full")) { 1384 duplex = RTE_ETH_LINK_FULL_DUPLEX; 1385 } else if (!strcmp(duplexstr, "auto")) { 1386 duplex = RTE_ETH_LINK_FULL_DUPLEX; 1387 } else { 1388 fprintf(stderr, "Unknown duplex parameter\n"); 1389 return -1; 1390 } 1391 1392 if (!strcmp(speedstr, "10")) { 1393 *speed = (duplex == RTE_ETH_LINK_HALF_DUPLEX) ? 1394 RTE_ETH_LINK_SPEED_10M_HD : RTE_ETH_LINK_SPEED_10M; 1395 } else if (!strcmp(speedstr, "100")) { 1396 *speed = (duplex == RTE_ETH_LINK_HALF_DUPLEX) ? 1397 RTE_ETH_LINK_SPEED_100M_HD : RTE_ETH_LINK_SPEED_100M; 1398 } else { 1399 if (duplex != RTE_ETH_LINK_FULL_DUPLEX) { 1400 fprintf(stderr, "Invalid speed/duplex parameters\n"); 1401 return -1; 1402 } 1403 if (!strcmp(speedstr, "1000")) { 1404 *speed = RTE_ETH_LINK_SPEED_1G; 1405 } else if (!strcmp(speedstr, "10000")) { 1406 *speed = RTE_ETH_LINK_SPEED_10G; 1407 } else if (!strcmp(speedstr, "25000")) { 1408 *speed = RTE_ETH_LINK_SPEED_25G; 1409 } else if (!strcmp(speedstr, "40000")) { 1410 *speed = RTE_ETH_LINK_SPEED_40G; 1411 } else if (!strcmp(speedstr, "50000")) { 1412 *speed = RTE_ETH_LINK_SPEED_50G; 1413 } else if (!strcmp(speedstr, "100000")) { 1414 *speed = RTE_ETH_LINK_SPEED_100G; 1415 } else if (!strcmp(speedstr, "200000")) { 1416 *speed = RTE_ETH_LINK_SPEED_200G; 1417 } else if (!strcmp(speedstr, "auto")) { 1418 *speed = RTE_ETH_LINK_SPEED_AUTONEG; 1419 } else { 1420 fprintf(stderr, "Unknown speed parameter\n"); 1421 return -1; 1422 } 1423 } 1424 1425 if (*speed != RTE_ETH_LINK_SPEED_AUTONEG) 1426 *speed |= RTE_ETH_LINK_SPEED_FIXED; 1427 1428 return 0; 1429 } 1430 1431 static void 1432 cmd_config_speed_all_parsed(void *parsed_result, 1433 __rte_unused struct cmdline *cl, 1434 __rte_unused void *data) 1435 { 1436 struct cmd_config_speed_all *res = parsed_result; 1437 uint32_t link_speed; 1438 portid_t pid; 1439 1440 if (!all_ports_stopped()) { 1441 fprintf(stderr, "Please stop all ports first\n"); 1442 return; 1443 } 1444 1445 if (parse_and_check_speed_duplex(res->value1, res->value2, 1446 &link_speed) < 0) 1447 return; 1448 1449 RTE_ETH_FOREACH_DEV(pid) { 1450 ports[pid].dev_conf.link_speeds = link_speed; 1451 } 1452 1453 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1454 } 1455 1456 static cmdline_parse_token_string_t cmd_config_speed_all_port = 1457 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port"); 1458 static cmdline_parse_token_string_t cmd_config_speed_all_keyword = 1459 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword, 1460 "config"); 1461 static cmdline_parse_token_string_t cmd_config_speed_all_all = 1462 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all"); 1463 static cmdline_parse_token_string_t cmd_config_speed_all_item1 = 1464 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed"); 1465 static cmdline_parse_token_string_t cmd_config_speed_all_value1 = 1466 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1, 1467 "10#100#1000#10000#25000#40000#50000#100000#200000#auto"); 1468 static cmdline_parse_token_string_t cmd_config_speed_all_item2 = 1469 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex"); 1470 static cmdline_parse_token_string_t cmd_config_speed_all_value2 = 1471 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2, 1472 "half#full#auto"); 1473 1474 static cmdline_parse_inst_t cmd_config_speed_all = { 1475 .f = cmd_config_speed_all_parsed, 1476 .data = NULL, 1477 .help_str = "port config all speed " 1478 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex " 1479 "half|full|auto", 1480 .tokens = { 1481 (void *)&cmd_config_speed_all_port, 1482 (void *)&cmd_config_speed_all_keyword, 1483 (void *)&cmd_config_speed_all_all, 1484 (void *)&cmd_config_speed_all_item1, 1485 (void *)&cmd_config_speed_all_value1, 1486 (void *)&cmd_config_speed_all_item2, 1487 (void *)&cmd_config_speed_all_value2, 1488 NULL, 1489 }, 1490 }; 1491 1492 /* *** configure speed for specific port *** */ 1493 struct cmd_config_speed_specific { 1494 cmdline_fixed_string_t port; 1495 cmdline_fixed_string_t keyword; 1496 portid_t id; 1497 cmdline_fixed_string_t item1; 1498 cmdline_fixed_string_t item2; 1499 cmdline_fixed_string_t value1; 1500 cmdline_fixed_string_t value2; 1501 }; 1502 1503 static void 1504 cmd_config_speed_specific_parsed(void *parsed_result, 1505 __rte_unused struct cmdline *cl, 1506 __rte_unused void *data) 1507 { 1508 struct cmd_config_speed_specific *res = parsed_result; 1509 uint32_t link_speed; 1510 1511 if (port_id_is_invalid(res->id, ENABLED_WARN)) 1512 return; 1513 1514 if (!port_is_stopped(res->id)) { 1515 fprintf(stderr, "Please stop port %d first\n", res->id); 1516 return; 1517 } 1518 1519 if (parse_and_check_speed_duplex(res->value1, res->value2, 1520 &link_speed) < 0) 1521 return; 1522 1523 ports[res->id].dev_conf.link_speeds = link_speed; 1524 1525 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1526 } 1527 1528 1529 static cmdline_parse_token_string_t cmd_config_speed_specific_port = 1530 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port, 1531 "port"); 1532 static cmdline_parse_token_string_t cmd_config_speed_specific_keyword = 1533 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword, 1534 "config"); 1535 static cmdline_parse_token_num_t cmd_config_speed_specific_id = 1536 TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, RTE_UINT16); 1537 static cmdline_parse_token_string_t cmd_config_speed_specific_item1 = 1538 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1, 1539 "speed"); 1540 static cmdline_parse_token_string_t cmd_config_speed_specific_value1 = 1541 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1, 1542 "10#100#1000#10000#25000#40000#50000#100000#200000#auto"); 1543 static cmdline_parse_token_string_t cmd_config_speed_specific_item2 = 1544 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2, 1545 "duplex"); 1546 static cmdline_parse_token_string_t cmd_config_speed_specific_value2 = 1547 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2, 1548 "half#full#auto"); 1549 1550 static cmdline_parse_inst_t cmd_config_speed_specific = { 1551 .f = cmd_config_speed_specific_parsed, 1552 .data = NULL, 1553 .help_str = "port config <port_id> speed " 1554 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex " 1555 "half|full|auto", 1556 .tokens = { 1557 (void *)&cmd_config_speed_specific_port, 1558 (void *)&cmd_config_speed_specific_keyword, 1559 (void *)&cmd_config_speed_specific_id, 1560 (void *)&cmd_config_speed_specific_item1, 1561 (void *)&cmd_config_speed_specific_value1, 1562 (void *)&cmd_config_speed_specific_item2, 1563 (void *)&cmd_config_speed_specific_value2, 1564 NULL, 1565 }, 1566 }; 1567 1568 /* *** configure loopback for all ports *** */ 1569 struct cmd_config_loopback_all { 1570 cmdline_fixed_string_t port; 1571 cmdline_fixed_string_t keyword; 1572 cmdline_fixed_string_t all; 1573 cmdline_fixed_string_t item; 1574 uint32_t mode; 1575 }; 1576 1577 static void 1578 cmd_config_loopback_all_parsed(void *parsed_result, 1579 __rte_unused struct cmdline *cl, 1580 __rte_unused void *data) 1581 { 1582 struct cmd_config_loopback_all *res = parsed_result; 1583 portid_t pid; 1584 1585 if (!all_ports_stopped()) { 1586 fprintf(stderr, "Please stop all ports first\n"); 1587 return; 1588 } 1589 1590 RTE_ETH_FOREACH_DEV(pid) { 1591 ports[pid].dev_conf.lpbk_mode = res->mode; 1592 } 1593 1594 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1595 } 1596 1597 static cmdline_parse_token_string_t cmd_config_loopback_all_port = 1598 TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port"); 1599 static cmdline_parse_token_string_t cmd_config_loopback_all_keyword = 1600 TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword, 1601 "config"); 1602 static cmdline_parse_token_string_t cmd_config_loopback_all_all = 1603 TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all"); 1604 static cmdline_parse_token_string_t cmd_config_loopback_all_item = 1605 TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item, 1606 "loopback"); 1607 static cmdline_parse_token_num_t cmd_config_loopback_all_mode = 1608 TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, RTE_UINT32); 1609 1610 static cmdline_parse_inst_t cmd_config_loopback_all = { 1611 .f = cmd_config_loopback_all_parsed, 1612 .data = NULL, 1613 .help_str = "port config all loopback <mode>", 1614 .tokens = { 1615 (void *)&cmd_config_loopback_all_port, 1616 (void *)&cmd_config_loopback_all_keyword, 1617 (void *)&cmd_config_loopback_all_all, 1618 (void *)&cmd_config_loopback_all_item, 1619 (void *)&cmd_config_loopback_all_mode, 1620 NULL, 1621 }, 1622 }; 1623 1624 /* *** configure loopback for specific port *** */ 1625 struct cmd_config_loopback_specific { 1626 cmdline_fixed_string_t port; 1627 cmdline_fixed_string_t keyword; 1628 uint16_t port_id; 1629 cmdline_fixed_string_t item; 1630 uint32_t mode; 1631 }; 1632 1633 static void 1634 cmd_config_loopback_specific_parsed(void *parsed_result, 1635 __rte_unused struct cmdline *cl, 1636 __rte_unused void *data) 1637 { 1638 struct cmd_config_loopback_specific *res = parsed_result; 1639 1640 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 1641 return; 1642 1643 if (!port_is_stopped(res->port_id)) { 1644 fprintf(stderr, "Please stop port %u first\n", res->port_id); 1645 return; 1646 } 1647 1648 ports[res->port_id].dev_conf.lpbk_mode = res->mode; 1649 1650 cmd_reconfig_device_queue(res->port_id, 1, 1); 1651 } 1652 1653 1654 static cmdline_parse_token_string_t cmd_config_loopback_specific_port = 1655 TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port, 1656 "port"); 1657 static cmdline_parse_token_string_t cmd_config_loopback_specific_keyword = 1658 TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword, 1659 "config"); 1660 static cmdline_parse_token_num_t cmd_config_loopback_specific_id = 1661 TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id, 1662 RTE_UINT16); 1663 static cmdline_parse_token_string_t cmd_config_loopback_specific_item = 1664 TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item, 1665 "loopback"); 1666 static cmdline_parse_token_num_t cmd_config_loopback_specific_mode = 1667 TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode, 1668 RTE_UINT32); 1669 1670 static cmdline_parse_inst_t cmd_config_loopback_specific = { 1671 .f = cmd_config_loopback_specific_parsed, 1672 .data = NULL, 1673 .help_str = "port config <port_id> loopback <mode>", 1674 .tokens = { 1675 (void *)&cmd_config_loopback_specific_port, 1676 (void *)&cmd_config_loopback_specific_keyword, 1677 (void *)&cmd_config_loopback_specific_id, 1678 (void *)&cmd_config_loopback_specific_item, 1679 (void *)&cmd_config_loopback_specific_mode, 1680 NULL, 1681 }, 1682 }; 1683 1684 /* *** configure txq/rxq, txd/rxd *** */ 1685 struct cmd_config_rx_tx { 1686 cmdline_fixed_string_t port; 1687 cmdline_fixed_string_t keyword; 1688 cmdline_fixed_string_t all; 1689 cmdline_fixed_string_t name; 1690 uint16_t value; 1691 }; 1692 1693 static void 1694 cmd_config_rx_tx_parsed(void *parsed_result, 1695 __rte_unused struct cmdline *cl, 1696 __rte_unused void *data) 1697 { 1698 struct cmd_config_rx_tx *res = parsed_result; 1699 1700 if (!all_ports_stopped()) { 1701 fprintf(stderr, "Please stop all ports first\n"); 1702 return; 1703 } 1704 if (!strcmp(res->name, "rxq")) { 1705 if (!res->value && !nb_txq) { 1706 fprintf(stderr, "Warning: Either rx or tx queues should be non zero\n"); 1707 return; 1708 } 1709 if (check_nb_rxq(res->value) != 0) 1710 return; 1711 nb_rxq = res->value; 1712 } 1713 else if (!strcmp(res->name, "txq")) { 1714 if (!res->value && !nb_rxq) { 1715 fprintf(stderr, "Warning: Either rx or tx queues should be non zero\n"); 1716 return; 1717 } 1718 if (check_nb_txq(res->value) != 0) 1719 return; 1720 nb_txq = res->value; 1721 } 1722 else if (!strcmp(res->name, "rxd")) { 1723 if (check_nb_rxd(res->value) != 0) 1724 return; 1725 nb_rxd = res->value; 1726 } else if (!strcmp(res->name, "txd")) { 1727 if (check_nb_txd(res->value) != 0) 1728 return; 1729 1730 nb_txd = res->value; 1731 } else { 1732 fprintf(stderr, "Unknown parameter\n"); 1733 return; 1734 } 1735 1736 fwd_config_setup(); 1737 1738 init_port_config(); 1739 1740 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1741 } 1742 1743 static cmdline_parse_token_string_t cmd_config_rx_tx_port = 1744 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port"); 1745 static cmdline_parse_token_string_t cmd_config_rx_tx_keyword = 1746 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config"); 1747 static cmdline_parse_token_string_t cmd_config_rx_tx_all = 1748 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all"); 1749 static cmdline_parse_token_string_t cmd_config_rx_tx_name = 1750 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name, 1751 "rxq#txq#rxd#txd"); 1752 static cmdline_parse_token_num_t cmd_config_rx_tx_value = 1753 TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, RTE_UINT16); 1754 1755 static cmdline_parse_inst_t cmd_config_rx_tx = { 1756 .f = cmd_config_rx_tx_parsed, 1757 .data = NULL, 1758 .help_str = "port config all rxq|txq|rxd|txd <value>", 1759 .tokens = { 1760 (void *)&cmd_config_rx_tx_port, 1761 (void *)&cmd_config_rx_tx_keyword, 1762 (void *)&cmd_config_rx_tx_all, 1763 (void *)&cmd_config_rx_tx_name, 1764 (void *)&cmd_config_rx_tx_value, 1765 NULL, 1766 }, 1767 }; 1768 1769 /* *** config max packet length *** */ 1770 struct cmd_config_max_pkt_len_result { 1771 cmdline_fixed_string_t port; 1772 cmdline_fixed_string_t keyword; 1773 cmdline_fixed_string_t all; 1774 cmdline_fixed_string_t name; 1775 uint32_t value; 1776 }; 1777 1778 static void 1779 cmd_config_max_pkt_len_parsed(void *parsed_result, 1780 __rte_unused struct cmdline *cl, 1781 __rte_unused void *data) 1782 { 1783 struct cmd_config_max_pkt_len_result *res = parsed_result; 1784 portid_t port_id; 1785 int ret; 1786 1787 if (strcmp(res->name, "max-pkt-len") != 0) { 1788 printf("Unknown parameter\n"); 1789 return; 1790 } 1791 1792 if (!all_ports_stopped()) { 1793 fprintf(stderr, "Please stop all ports first\n"); 1794 return; 1795 } 1796 1797 RTE_ETH_FOREACH_DEV(port_id) { 1798 struct rte_port *port = &ports[port_id]; 1799 1800 if (res->value < RTE_ETHER_MIN_LEN) { 1801 fprintf(stderr, 1802 "max-pkt-len can not be less than %d\n", 1803 RTE_ETHER_MIN_LEN); 1804 return; 1805 } 1806 1807 ret = eth_dev_info_get_print_err(port_id, &port->dev_info); 1808 if (ret != 0) { 1809 fprintf(stderr, 1810 "rte_eth_dev_info_get() failed for port %u\n", 1811 port_id); 1812 return; 1813 } 1814 1815 update_mtu_from_frame_size(port_id, res->value); 1816 } 1817 1818 init_port_config(); 1819 1820 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1821 } 1822 1823 static cmdline_parse_token_string_t cmd_config_max_pkt_len_port = 1824 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port, 1825 "port"); 1826 static cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword = 1827 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword, 1828 "config"); 1829 static cmdline_parse_token_string_t cmd_config_max_pkt_len_all = 1830 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all, 1831 "all"); 1832 static cmdline_parse_token_string_t cmd_config_max_pkt_len_name = 1833 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name, 1834 "max-pkt-len"); 1835 static cmdline_parse_token_num_t cmd_config_max_pkt_len_value = 1836 TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value, 1837 RTE_UINT32); 1838 1839 static cmdline_parse_inst_t cmd_config_max_pkt_len = { 1840 .f = cmd_config_max_pkt_len_parsed, 1841 .data = NULL, 1842 .help_str = "port config all max-pkt-len <value>", 1843 .tokens = { 1844 (void *)&cmd_config_max_pkt_len_port, 1845 (void *)&cmd_config_max_pkt_len_keyword, 1846 (void *)&cmd_config_max_pkt_len_all, 1847 (void *)&cmd_config_max_pkt_len_name, 1848 (void *)&cmd_config_max_pkt_len_value, 1849 NULL, 1850 }, 1851 }; 1852 1853 /* *** config max LRO aggregated packet size *** */ 1854 struct cmd_config_max_lro_pkt_size_result { 1855 cmdline_fixed_string_t port; 1856 cmdline_fixed_string_t keyword; 1857 cmdline_fixed_string_t all; 1858 cmdline_fixed_string_t name; 1859 uint32_t value; 1860 }; 1861 1862 static void 1863 cmd_config_max_lro_pkt_size_parsed(void *parsed_result, 1864 __rte_unused struct cmdline *cl, 1865 __rte_unused void *data) 1866 { 1867 struct cmd_config_max_lro_pkt_size_result *res = parsed_result; 1868 portid_t pid; 1869 1870 if (!all_ports_stopped()) { 1871 fprintf(stderr, "Please stop all ports first\n"); 1872 return; 1873 } 1874 1875 RTE_ETH_FOREACH_DEV(pid) { 1876 struct rte_port *port = &ports[pid]; 1877 1878 if (!strcmp(res->name, "max-lro-pkt-size")) { 1879 if (res->value == 1880 port->dev_conf.rxmode.max_lro_pkt_size) 1881 return; 1882 1883 port->dev_conf.rxmode.max_lro_pkt_size = res->value; 1884 } else { 1885 fprintf(stderr, "Unknown parameter\n"); 1886 return; 1887 } 1888 } 1889 1890 init_port_config(); 1891 1892 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1893 } 1894 1895 static cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port = 1896 TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result, 1897 port, "port"); 1898 static cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword = 1899 TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result, 1900 keyword, "config"); 1901 static cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all = 1902 TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result, 1903 all, "all"); 1904 static cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name = 1905 TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result, 1906 name, "max-lro-pkt-size"); 1907 static cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value = 1908 TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result, 1909 value, RTE_UINT32); 1910 1911 static cmdline_parse_inst_t cmd_config_max_lro_pkt_size = { 1912 .f = cmd_config_max_lro_pkt_size_parsed, 1913 .data = NULL, 1914 .help_str = "port config all max-lro-pkt-size <value>", 1915 .tokens = { 1916 (void *)&cmd_config_max_lro_pkt_size_port, 1917 (void *)&cmd_config_max_lro_pkt_size_keyword, 1918 (void *)&cmd_config_max_lro_pkt_size_all, 1919 (void *)&cmd_config_max_lro_pkt_size_name, 1920 (void *)&cmd_config_max_lro_pkt_size_value, 1921 NULL, 1922 }, 1923 }; 1924 1925 /* *** configure port MTU *** */ 1926 struct cmd_config_mtu_result { 1927 cmdline_fixed_string_t port; 1928 cmdline_fixed_string_t keyword; 1929 cmdline_fixed_string_t mtu; 1930 portid_t port_id; 1931 uint16_t value; 1932 }; 1933 1934 static void 1935 cmd_config_mtu_parsed(void *parsed_result, 1936 __rte_unused struct cmdline *cl, 1937 __rte_unused void *data) 1938 { 1939 struct cmd_config_mtu_result *res = parsed_result; 1940 1941 port_mtu_set(res->port_id, res->value); 1942 } 1943 1944 static cmdline_parse_token_string_t cmd_config_mtu_port = 1945 TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port, 1946 "port"); 1947 static cmdline_parse_token_string_t cmd_config_mtu_keyword = 1948 TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword, 1949 "config"); 1950 static cmdline_parse_token_string_t cmd_config_mtu_mtu = 1951 TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword, 1952 "mtu"); 1953 static cmdline_parse_token_num_t cmd_config_mtu_port_id = 1954 TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, 1955 RTE_UINT16); 1956 static cmdline_parse_token_num_t cmd_config_mtu_value = 1957 TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, 1958 RTE_UINT16); 1959 1960 static cmdline_parse_inst_t cmd_config_mtu = { 1961 .f = cmd_config_mtu_parsed, 1962 .data = NULL, 1963 .help_str = "port config mtu <port_id> <value>", 1964 .tokens = { 1965 (void *)&cmd_config_mtu_port, 1966 (void *)&cmd_config_mtu_keyword, 1967 (void *)&cmd_config_mtu_mtu, 1968 (void *)&cmd_config_mtu_port_id, 1969 (void *)&cmd_config_mtu_value, 1970 NULL, 1971 }, 1972 }; 1973 1974 /* *** configure rx mode *** */ 1975 struct cmd_config_rx_mode_flag { 1976 cmdline_fixed_string_t port; 1977 cmdline_fixed_string_t keyword; 1978 cmdline_fixed_string_t all; 1979 cmdline_fixed_string_t name; 1980 cmdline_fixed_string_t value; 1981 }; 1982 1983 static void 1984 cmd_config_rx_mode_flag_parsed(void *parsed_result, 1985 __rte_unused struct cmdline *cl, 1986 __rte_unused void *data) 1987 { 1988 struct cmd_config_rx_mode_flag *res = parsed_result; 1989 1990 if (!all_ports_stopped()) { 1991 fprintf(stderr, "Please stop all ports first\n"); 1992 return; 1993 } 1994 1995 if (!strcmp(res->name, "drop-en")) { 1996 if (!strcmp(res->value, "on")) 1997 rx_drop_en = 1; 1998 else if (!strcmp(res->value, "off")) 1999 rx_drop_en = 0; 2000 else { 2001 fprintf(stderr, "Unknown parameter\n"); 2002 return; 2003 } 2004 } else { 2005 fprintf(stderr, "Unknown parameter\n"); 2006 return; 2007 } 2008 2009 init_port_config(); 2010 2011 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 2012 } 2013 2014 static cmdline_parse_token_string_t cmd_config_rx_mode_flag_port = 2015 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port"); 2016 static cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword = 2017 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword, 2018 "config"); 2019 static cmdline_parse_token_string_t cmd_config_rx_mode_flag_all = 2020 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all"); 2021 static cmdline_parse_token_string_t cmd_config_rx_mode_flag_name = 2022 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name, 2023 "drop-en"); 2024 static cmdline_parse_token_string_t cmd_config_rx_mode_flag_value = 2025 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value, 2026 "on#off"); 2027 2028 static cmdline_parse_inst_t cmd_config_rx_mode_flag = { 2029 .f = cmd_config_rx_mode_flag_parsed, 2030 .data = NULL, 2031 .help_str = "port config all drop-en on|off", 2032 .tokens = { 2033 (void *)&cmd_config_rx_mode_flag_port, 2034 (void *)&cmd_config_rx_mode_flag_keyword, 2035 (void *)&cmd_config_rx_mode_flag_all, 2036 (void *)&cmd_config_rx_mode_flag_name, 2037 (void *)&cmd_config_rx_mode_flag_value, 2038 NULL, 2039 }, 2040 }; 2041 2042 /* *** configure rss *** */ 2043 struct cmd_config_rss { 2044 cmdline_fixed_string_t port; 2045 cmdline_fixed_string_t keyword; 2046 cmdline_fixed_string_t all; 2047 cmdline_fixed_string_t name; 2048 cmdline_fixed_string_t value; 2049 }; 2050 2051 static void 2052 cmd_config_rss_parsed(void *parsed_result, 2053 __rte_unused struct cmdline *cl, 2054 __rte_unused void *data) 2055 { 2056 struct cmd_config_rss *res = parsed_result; 2057 struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, }; 2058 struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, }; 2059 int use_default = 0; 2060 int all_updated = 1; 2061 int diag; 2062 uint16_t i; 2063 int ret; 2064 2065 if (!strcmp(res->value, "all")) 2066 rss_conf.rss_hf = RTE_ETH_RSS_ETH | RTE_ETH_RSS_VLAN | RTE_ETH_RSS_IP | 2067 RTE_ETH_RSS_TCP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_SCTP | 2068 RTE_ETH_RSS_L2_PAYLOAD | RTE_ETH_RSS_L2TPV3 | RTE_ETH_RSS_ESP | 2069 RTE_ETH_RSS_AH | RTE_ETH_RSS_PFCP | RTE_ETH_RSS_GTPU | 2070 RTE_ETH_RSS_ECPRI | RTE_ETH_RSS_L2TPV2; 2071 else if (!strcmp(res->value, "eth")) 2072 rss_conf.rss_hf = RTE_ETH_RSS_ETH; 2073 else if (!strcmp(res->value, "vlan")) 2074 rss_conf.rss_hf = RTE_ETH_RSS_VLAN; 2075 else if (!strcmp(res->value, "ip")) 2076 rss_conf.rss_hf = RTE_ETH_RSS_IP; 2077 else if (!strcmp(res->value, "udp")) 2078 rss_conf.rss_hf = RTE_ETH_RSS_UDP; 2079 else if (!strcmp(res->value, "tcp")) 2080 rss_conf.rss_hf = RTE_ETH_RSS_TCP; 2081 else if (!strcmp(res->value, "sctp")) 2082 rss_conf.rss_hf = RTE_ETH_RSS_SCTP; 2083 else if (!strcmp(res->value, "ether")) 2084 rss_conf.rss_hf = RTE_ETH_RSS_L2_PAYLOAD; 2085 else if (!strcmp(res->value, "port")) 2086 rss_conf.rss_hf = RTE_ETH_RSS_PORT; 2087 else if (!strcmp(res->value, "vxlan")) 2088 rss_conf.rss_hf = RTE_ETH_RSS_VXLAN; 2089 else if (!strcmp(res->value, "geneve")) 2090 rss_conf.rss_hf = RTE_ETH_RSS_GENEVE; 2091 else if (!strcmp(res->value, "nvgre")) 2092 rss_conf.rss_hf = RTE_ETH_RSS_NVGRE; 2093 else if (!strcmp(res->value, "l3-pre32")) 2094 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32; 2095 else if (!strcmp(res->value, "l3-pre40")) 2096 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40; 2097 else if (!strcmp(res->value, "l3-pre48")) 2098 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48; 2099 else if (!strcmp(res->value, "l3-pre56")) 2100 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56; 2101 else if (!strcmp(res->value, "l3-pre64")) 2102 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64; 2103 else if (!strcmp(res->value, "l3-pre96")) 2104 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96; 2105 else if (!strcmp(res->value, "l3-src-only")) 2106 rss_conf.rss_hf = RTE_ETH_RSS_L3_SRC_ONLY; 2107 else if (!strcmp(res->value, "l3-dst-only")) 2108 rss_conf.rss_hf = RTE_ETH_RSS_L3_DST_ONLY; 2109 else if (!strcmp(res->value, "l4-src-only")) 2110 rss_conf.rss_hf = RTE_ETH_RSS_L4_SRC_ONLY; 2111 else if (!strcmp(res->value, "l4-dst-only")) 2112 rss_conf.rss_hf = RTE_ETH_RSS_L4_DST_ONLY; 2113 else if (!strcmp(res->value, "l2-src-only")) 2114 rss_conf.rss_hf = RTE_ETH_RSS_L2_SRC_ONLY; 2115 else if (!strcmp(res->value, "l2-dst-only")) 2116 rss_conf.rss_hf = RTE_ETH_RSS_L2_DST_ONLY; 2117 else if (!strcmp(res->value, "l2tpv3")) 2118 rss_conf.rss_hf = RTE_ETH_RSS_L2TPV3; 2119 else if (!strcmp(res->value, "esp")) 2120 rss_conf.rss_hf = RTE_ETH_RSS_ESP; 2121 else if (!strcmp(res->value, "ah")) 2122 rss_conf.rss_hf = RTE_ETH_RSS_AH; 2123 else if (!strcmp(res->value, "pfcp")) 2124 rss_conf.rss_hf = RTE_ETH_RSS_PFCP; 2125 else if (!strcmp(res->value, "pppoe")) 2126 rss_conf.rss_hf = RTE_ETH_RSS_PPPOE; 2127 else if (!strcmp(res->value, "gtpu")) 2128 rss_conf.rss_hf = RTE_ETH_RSS_GTPU; 2129 else if (!strcmp(res->value, "ecpri")) 2130 rss_conf.rss_hf = RTE_ETH_RSS_ECPRI; 2131 else if (!strcmp(res->value, "mpls")) 2132 rss_conf.rss_hf = RTE_ETH_RSS_MPLS; 2133 else if (!strcmp(res->value, "ipv4-chksum")) 2134 rss_conf.rss_hf = RTE_ETH_RSS_IPV4_CHKSUM; 2135 else if (!strcmp(res->value, "l2tpv2")) 2136 rss_conf.rss_hf = RTE_ETH_RSS_L2TPV2; 2137 else if (!strcmp(res->value, "none")) 2138 rss_conf.rss_hf = 0; 2139 else if (!strcmp(res->value, "level-default")) { 2140 rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK); 2141 rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_PMD_DEFAULT); 2142 } else if (!strcmp(res->value, "level-outer")) { 2143 rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK); 2144 rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_OUTERMOST); 2145 } else if (!strcmp(res->value, "level-inner")) { 2146 rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK); 2147 rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_INNERMOST); 2148 } else if (!strcmp(res->value, "default")) 2149 use_default = 1; 2150 else if (isdigit(res->value[0]) && atoi(res->value) > 0 && 2151 atoi(res->value) < 64) 2152 rss_conf.rss_hf = 1ULL << atoi(res->value); 2153 else { 2154 fprintf(stderr, "Unknown parameter\n"); 2155 return; 2156 } 2157 rss_conf.rss_key = NULL; 2158 /* Update global configuration for RSS types. */ 2159 RTE_ETH_FOREACH_DEV(i) { 2160 struct rte_eth_rss_conf local_rss_conf; 2161 2162 ret = eth_dev_info_get_print_err(i, &dev_info); 2163 if (ret != 0) 2164 return; 2165 2166 if (use_default) 2167 rss_conf.rss_hf = dev_info.flow_type_rss_offloads; 2168 2169 local_rss_conf = rss_conf; 2170 local_rss_conf.rss_hf = rss_conf.rss_hf & 2171 dev_info.flow_type_rss_offloads; 2172 if (local_rss_conf.rss_hf != rss_conf.rss_hf) { 2173 printf("Port %u modified RSS hash function based on hardware support," 2174 "requested:%#"PRIx64" configured:%#"PRIx64"\n", 2175 i, rss_conf.rss_hf, local_rss_conf.rss_hf); 2176 } 2177 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf); 2178 if (diag < 0) { 2179 all_updated = 0; 2180 fprintf(stderr, 2181 "Configuration of RSS hash at ethernet port %d failed with error (%d): %s.\n", 2182 i, -diag, strerror(-diag)); 2183 } 2184 } 2185 if (all_updated && !use_default) { 2186 rss_hf = rss_conf.rss_hf; 2187 printf("rss_hf %#"PRIx64"\n", rss_hf); 2188 } 2189 } 2190 2191 static cmdline_parse_token_string_t cmd_config_rss_port = 2192 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port"); 2193 static cmdline_parse_token_string_t cmd_config_rss_keyword = 2194 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config"); 2195 static cmdline_parse_token_string_t cmd_config_rss_all = 2196 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all"); 2197 static cmdline_parse_token_string_t cmd_config_rss_name = 2198 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss"); 2199 static cmdline_parse_token_string_t cmd_config_rss_value = 2200 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL); 2201 2202 static cmdline_parse_inst_t cmd_config_rss = { 2203 .f = cmd_config_rss_parsed, 2204 .data = NULL, 2205 .help_str = "port config all rss " 2206 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|" 2207 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|ecpri|mpls|ipv4-chksum|l2tpv2|" 2208 "none|level-default|level-outer|level-inner|<flowtype_id>", 2209 .tokens = { 2210 (void *)&cmd_config_rss_port, 2211 (void *)&cmd_config_rss_keyword, 2212 (void *)&cmd_config_rss_all, 2213 (void *)&cmd_config_rss_name, 2214 (void *)&cmd_config_rss_value, 2215 NULL, 2216 }, 2217 }; 2218 2219 /* *** configure rss hash key *** */ 2220 struct cmd_config_rss_hash_key { 2221 cmdline_fixed_string_t port; 2222 cmdline_fixed_string_t config; 2223 portid_t port_id; 2224 cmdline_fixed_string_t rss_hash_key; 2225 cmdline_fixed_string_t rss_type; 2226 cmdline_fixed_string_t key; 2227 }; 2228 2229 static uint8_t 2230 hexa_digit_to_value(char hexa_digit) 2231 { 2232 if ((hexa_digit >= '0') && (hexa_digit <= '9')) 2233 return (uint8_t) (hexa_digit - '0'); 2234 if ((hexa_digit >= 'a') && (hexa_digit <= 'f')) 2235 return (uint8_t) ((hexa_digit - 'a') + 10); 2236 if ((hexa_digit >= 'A') && (hexa_digit <= 'F')) 2237 return (uint8_t) ((hexa_digit - 'A') + 10); 2238 /* Invalid hexa digit */ 2239 return 0xFF; 2240 } 2241 2242 static uint8_t 2243 parse_and_check_key_hexa_digit(char *key, int idx) 2244 { 2245 uint8_t hexa_v; 2246 2247 hexa_v = hexa_digit_to_value(key[idx]); 2248 if (hexa_v == 0xFF) 2249 fprintf(stderr, 2250 "invalid key: character %c at position %d is not a valid hexa digit\n", 2251 key[idx], idx); 2252 return hexa_v; 2253 } 2254 2255 static void 2256 cmd_config_rss_hash_key_parsed(void *parsed_result, 2257 __rte_unused struct cmdline *cl, 2258 __rte_unused void *data) 2259 { 2260 struct cmd_config_rss_hash_key *res = parsed_result; 2261 uint8_t hash_key[RSS_HASH_KEY_LENGTH]; 2262 uint8_t xdgt0; 2263 uint8_t xdgt1; 2264 int i; 2265 struct rte_eth_dev_info dev_info; 2266 uint8_t hash_key_size; 2267 uint32_t key_len; 2268 int ret; 2269 2270 ret = eth_dev_info_get_print_err(res->port_id, &dev_info); 2271 if (ret != 0) 2272 return; 2273 2274 if (dev_info.hash_key_size > 0 && 2275 dev_info.hash_key_size <= sizeof(hash_key)) 2276 hash_key_size = dev_info.hash_key_size; 2277 else { 2278 fprintf(stderr, 2279 "dev_info did not provide a valid hash key size\n"); 2280 return; 2281 } 2282 /* Check the length of the RSS hash key */ 2283 key_len = strlen(res->key); 2284 if (key_len != (hash_key_size * 2)) { 2285 fprintf(stderr, 2286 "key length: %d invalid - key must be a string of %d hexa-decimal numbers\n", 2287 (int)key_len, hash_key_size * 2); 2288 return; 2289 } 2290 /* Translate RSS hash key into binary representation */ 2291 for (i = 0; i < hash_key_size; i++) { 2292 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2)); 2293 if (xdgt0 == 0xFF) 2294 return; 2295 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1); 2296 if (xdgt1 == 0xFF) 2297 return; 2298 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1); 2299 } 2300 port_rss_hash_key_update(res->port_id, res->rss_type, hash_key, 2301 hash_key_size); 2302 } 2303 2304 static cmdline_parse_token_string_t cmd_config_rss_hash_key_port = 2305 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port"); 2306 static cmdline_parse_token_string_t cmd_config_rss_hash_key_config = 2307 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config, 2308 "config"); 2309 static cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id = 2310 TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, 2311 RTE_UINT16); 2312 static cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key = 2313 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, 2314 rss_hash_key, "rss-hash-key"); 2315 static cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type = 2316 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type, 2317 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#" 2318 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#" 2319 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#" 2320 "ipv6-tcp-ex#ipv6-udp-ex#" 2321 "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#" 2322 "l2-src-only#l2-dst-only#s-vlan#c-vlan#" 2323 "l2tpv3#esp#ah#pfcp#pppoe#gtpu#ecpri#mpls#l2tpv2"); 2324 static cmdline_parse_token_string_t cmd_config_rss_hash_key_value = 2325 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL); 2326 2327 static cmdline_parse_inst_t cmd_config_rss_hash_key = { 2328 .f = cmd_config_rss_hash_key_parsed, 2329 .data = NULL, 2330 .help_str = "port config <port_id> rss-hash-key " 2331 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 2332 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 2333 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|" 2334 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|" 2335 "l2-src-only|l2-dst-only|s-vlan|c-vlan|" 2336 "l2tpv3|esp|ah|pfcp|pppoe|gtpu|ecpri|mpls|l2tpv2 " 2337 "<string of hex digits (variable length, NIC dependent)>", 2338 .tokens = { 2339 (void *)&cmd_config_rss_hash_key_port, 2340 (void *)&cmd_config_rss_hash_key_config, 2341 (void *)&cmd_config_rss_hash_key_port_id, 2342 (void *)&cmd_config_rss_hash_key_rss_hash_key, 2343 (void *)&cmd_config_rss_hash_key_rss_type, 2344 (void *)&cmd_config_rss_hash_key_value, 2345 NULL, 2346 }, 2347 }; 2348 2349 /* *** cleanup txq mbufs *** */ 2350 struct cmd_cleanup_txq_mbufs_result { 2351 cmdline_fixed_string_t port; 2352 cmdline_fixed_string_t keyword; 2353 cmdline_fixed_string_t name; 2354 uint16_t port_id; 2355 uint16_t queue_id; 2356 uint32_t free_cnt; 2357 }; 2358 2359 static void 2360 cmd_cleanup_txq_mbufs_parsed(void *parsed_result, 2361 __rte_unused struct cmdline *cl, 2362 __rte_unused void *data) 2363 { 2364 struct cmd_cleanup_txq_mbufs_result *res = parsed_result; 2365 uint16_t port_id = res->port_id; 2366 uint16_t queue_id = res->queue_id; 2367 uint32_t free_cnt = res->free_cnt; 2368 struct rte_eth_txq_info qinfo; 2369 int ret; 2370 2371 if (test_done == 0) { 2372 fprintf(stderr, "Please stop forwarding first\n"); 2373 return; 2374 } 2375 2376 if (rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo)) { 2377 fprintf(stderr, "Failed to get port %u Tx queue %u info\n", 2378 port_id, queue_id); 2379 return; 2380 } 2381 2382 if (qinfo.queue_state != RTE_ETH_QUEUE_STATE_STARTED) { 2383 fprintf(stderr, "Tx queue %u not started\n", queue_id); 2384 return; 2385 } 2386 2387 ret = rte_eth_tx_done_cleanup(port_id, queue_id, free_cnt); 2388 if (ret < 0) { 2389 fprintf(stderr, 2390 "Failed to cleanup mbuf for port %u Tx queue %u error desc: %s(%d)\n", 2391 port_id, queue_id, strerror(-ret), ret); 2392 return; 2393 } 2394 2395 printf("Cleanup port %u Tx queue %u mbuf nums: %u\n", 2396 port_id, queue_id, ret); 2397 } 2398 2399 static cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_port = 2400 TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port, 2401 "port"); 2402 static cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_cleanup = 2403 TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, keyword, 2404 "cleanup"); 2405 static cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_port_id = 2406 TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port_id, 2407 RTE_UINT16); 2408 static cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_txq = 2409 TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, name, 2410 "txq"); 2411 static cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_queue_id = 2412 TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, queue_id, 2413 RTE_UINT16); 2414 static cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_free_cnt = 2415 TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, free_cnt, 2416 RTE_UINT32); 2417 2418 static cmdline_parse_inst_t cmd_cleanup_txq_mbufs = { 2419 .f = cmd_cleanup_txq_mbufs_parsed, 2420 .data = NULL, 2421 .help_str = "port cleanup <port_id> txq <queue_id> <free_cnt>", 2422 .tokens = { 2423 (void *)&cmd_cleanup_txq_mbufs_port, 2424 (void *)&cmd_cleanup_txq_mbufs_cleanup, 2425 (void *)&cmd_cleanup_txq_mbufs_port_id, 2426 (void *)&cmd_cleanup_txq_mbufs_txq, 2427 (void *)&cmd_cleanup_txq_mbufs_queue_id, 2428 (void *)&cmd_cleanup_txq_mbufs_free_cnt, 2429 NULL, 2430 }, 2431 }; 2432 2433 /* *** configure port rxq/txq ring size *** */ 2434 struct cmd_config_rxtx_ring_size { 2435 cmdline_fixed_string_t port; 2436 cmdline_fixed_string_t config; 2437 portid_t portid; 2438 cmdline_fixed_string_t rxtxq; 2439 uint16_t qid; 2440 cmdline_fixed_string_t rsize; 2441 uint16_t size; 2442 }; 2443 2444 static void 2445 cmd_config_rxtx_ring_size_parsed(void *parsed_result, 2446 __rte_unused struct cmdline *cl, 2447 __rte_unused void *data) 2448 { 2449 struct cmd_config_rxtx_ring_size *res = parsed_result; 2450 struct rte_port *port; 2451 uint8_t isrx; 2452 2453 if (port_id_is_invalid(res->portid, ENABLED_WARN)) 2454 return; 2455 2456 if (res->portid == (portid_t)RTE_PORT_ALL) { 2457 fprintf(stderr, "Invalid port id\n"); 2458 return; 2459 } 2460 2461 port = &ports[res->portid]; 2462 2463 if (!strcmp(res->rxtxq, "rxq")) 2464 isrx = 1; 2465 else if (!strcmp(res->rxtxq, "txq")) 2466 isrx = 0; 2467 else { 2468 fprintf(stderr, "Unknown parameter\n"); 2469 return; 2470 } 2471 2472 if (isrx && rx_queue_id_is_invalid(res->qid)) 2473 return; 2474 else if (!isrx && tx_queue_id_is_invalid(res->qid)) 2475 return; 2476 2477 if (isrx && res->size != 0 && res->size <= rx_free_thresh) { 2478 fprintf(stderr, 2479 "Invalid rx ring_size, must > rx_free_thresh: %d\n", 2480 rx_free_thresh); 2481 return; 2482 } 2483 2484 if (isrx) 2485 port->nb_rx_desc[res->qid] = res->size; 2486 else 2487 port->nb_tx_desc[res->qid] = res->size; 2488 2489 cmd_reconfig_device_queue(res->portid, 0, 1); 2490 } 2491 2492 static cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port = 2493 TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size, 2494 port, "port"); 2495 static cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config = 2496 TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size, 2497 config, "config"); 2498 static cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid = 2499 TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size, 2500 portid, RTE_UINT16); 2501 static cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq = 2502 TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size, 2503 rxtxq, "rxq#txq"); 2504 static cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid = 2505 TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size, 2506 qid, RTE_UINT16); 2507 static cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize = 2508 TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size, 2509 rsize, "ring_size"); 2510 static cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size = 2511 TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size, 2512 size, RTE_UINT16); 2513 2514 static cmdline_parse_inst_t cmd_config_rxtx_ring_size = { 2515 .f = cmd_config_rxtx_ring_size_parsed, 2516 .data = NULL, 2517 .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>", 2518 .tokens = { 2519 (void *)&cmd_config_rxtx_ring_size_port, 2520 (void *)&cmd_config_rxtx_ring_size_config, 2521 (void *)&cmd_config_rxtx_ring_size_portid, 2522 (void *)&cmd_config_rxtx_ring_size_rxtxq, 2523 (void *)&cmd_config_rxtx_ring_size_qid, 2524 (void *)&cmd_config_rxtx_ring_size_rsize, 2525 (void *)&cmd_config_rxtx_ring_size_size, 2526 NULL, 2527 }, 2528 }; 2529 2530 /* *** configure port rxq/txq start/stop *** */ 2531 struct cmd_config_rxtx_queue { 2532 cmdline_fixed_string_t port; 2533 portid_t portid; 2534 cmdline_fixed_string_t rxtxq; 2535 uint16_t qid; 2536 cmdline_fixed_string_t opname; 2537 }; 2538 2539 static void 2540 cmd_config_rxtx_queue_parsed(void *parsed_result, 2541 __rte_unused struct cmdline *cl, 2542 __rte_unused void *data) 2543 { 2544 struct cmd_config_rxtx_queue *res = parsed_result; 2545 struct rte_port *port; 2546 uint8_t isrx; 2547 uint8_t isstart; 2548 uint8_t *state; 2549 int ret = 0; 2550 2551 if (test_done == 0) { 2552 fprintf(stderr, "Please stop forwarding first\n"); 2553 return; 2554 } 2555 2556 if (port_id_is_invalid(res->portid, ENABLED_WARN)) 2557 return; 2558 2559 if (port_is_started(res->portid) != 1) { 2560 fprintf(stderr, "Please start port %u first\n", res->portid); 2561 return; 2562 } 2563 2564 if (!strcmp(res->rxtxq, "rxq")) 2565 isrx = 1; 2566 else if (!strcmp(res->rxtxq, "txq")) 2567 isrx = 0; 2568 else { 2569 fprintf(stderr, "Unknown parameter\n"); 2570 return; 2571 } 2572 2573 if (isrx && rx_queue_id_is_invalid(res->qid)) 2574 return; 2575 else if (!isrx && tx_queue_id_is_invalid(res->qid)) 2576 return; 2577 2578 if (!strcmp(res->opname, "start")) 2579 isstart = 1; 2580 else if (!strcmp(res->opname, "stop")) 2581 isstart = 0; 2582 else { 2583 fprintf(stderr, "Unknown parameter\n"); 2584 return; 2585 } 2586 2587 if (isstart && isrx) 2588 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid); 2589 else if (!isstart && isrx) 2590 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid); 2591 else if (isstart && !isrx) 2592 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid); 2593 else 2594 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid); 2595 2596 if (ret == -ENOTSUP) { 2597 fprintf(stderr, "Function not supported in PMD\n"); 2598 return; 2599 } 2600 2601 port = &ports[res->portid]; 2602 state = isrx ? &port->rxq[res->qid].state : &port->txq[res->qid].state; 2603 *state = isstart ? RTE_ETH_QUEUE_STATE_STARTED : 2604 RTE_ETH_QUEUE_STATE_STOPPED; 2605 } 2606 2607 static cmdline_parse_token_string_t cmd_config_rxtx_queue_port = 2608 TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port"); 2609 static cmdline_parse_token_num_t cmd_config_rxtx_queue_portid = 2610 TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, RTE_UINT16); 2611 static cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq = 2612 TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq"); 2613 static cmdline_parse_token_num_t cmd_config_rxtx_queue_qid = 2614 TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, RTE_UINT16); 2615 static cmdline_parse_token_string_t cmd_config_rxtx_queue_opname = 2616 TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname, 2617 "start#stop"); 2618 2619 static cmdline_parse_inst_t cmd_config_rxtx_queue = { 2620 .f = cmd_config_rxtx_queue_parsed, 2621 .data = NULL, 2622 .help_str = "port <port_id> rxq|txq <queue_id> start|stop", 2623 .tokens = { 2624 (void *)&cmd_config_rxtx_queue_port, 2625 (void *)&cmd_config_rxtx_queue_portid, 2626 (void *)&cmd_config_rxtx_queue_rxtxq, 2627 (void *)&cmd_config_rxtx_queue_qid, 2628 (void *)&cmd_config_rxtx_queue_opname, 2629 NULL, 2630 }, 2631 }; 2632 2633 /* *** configure port rxq/txq deferred start on/off *** */ 2634 struct cmd_config_deferred_start_rxtx_queue { 2635 cmdline_fixed_string_t port; 2636 portid_t port_id; 2637 cmdline_fixed_string_t rxtxq; 2638 uint16_t qid; 2639 cmdline_fixed_string_t opname; 2640 cmdline_fixed_string_t state; 2641 }; 2642 2643 static void 2644 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result, 2645 __rte_unused struct cmdline *cl, 2646 __rte_unused void *data) 2647 { 2648 struct cmd_config_deferred_start_rxtx_queue *res = parsed_result; 2649 struct rte_port *port; 2650 uint8_t isrx; 2651 uint8_t ison; 2652 uint8_t needreconfig = 0; 2653 2654 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 2655 return; 2656 2657 if (port_is_started(res->port_id) != 0) { 2658 fprintf(stderr, "Please stop port %u first\n", res->port_id); 2659 return; 2660 } 2661 2662 port = &ports[res->port_id]; 2663 2664 isrx = !strcmp(res->rxtxq, "rxq"); 2665 2666 if (isrx && rx_queue_id_is_invalid(res->qid)) 2667 return; 2668 else if (!isrx && tx_queue_id_is_invalid(res->qid)) 2669 return; 2670 2671 ison = !strcmp(res->state, "on"); 2672 2673 if (isrx && port->rxq[res->qid].conf.rx_deferred_start != ison) { 2674 port->rxq[res->qid].conf.rx_deferred_start = ison; 2675 needreconfig = 1; 2676 } else if (!isrx && port->txq[res->qid].conf.tx_deferred_start != ison) { 2677 port->txq[res->qid].conf.tx_deferred_start = ison; 2678 needreconfig = 1; 2679 } 2680 2681 if (needreconfig) 2682 cmd_reconfig_device_queue(res->port_id, 0, 1); 2683 } 2684 2685 static cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port = 2686 TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue, 2687 port, "port"); 2688 static cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id = 2689 TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue, 2690 port_id, RTE_UINT16); 2691 static cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq = 2692 TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue, 2693 rxtxq, "rxq#txq"); 2694 static cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid = 2695 TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue, 2696 qid, RTE_UINT16); 2697 static cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname = 2698 TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue, 2699 opname, "deferred_start"); 2700 static cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state = 2701 TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue, 2702 state, "on#off"); 2703 2704 static cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = { 2705 .f = cmd_config_deferred_start_rxtx_queue_parsed, 2706 .data = NULL, 2707 .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off", 2708 .tokens = { 2709 (void *)&cmd_config_deferred_start_rxtx_queue_port, 2710 (void *)&cmd_config_deferred_start_rxtx_queue_port_id, 2711 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq, 2712 (void *)&cmd_config_deferred_start_rxtx_queue_qid, 2713 (void *)&cmd_config_deferred_start_rxtx_queue_opname, 2714 (void *)&cmd_config_deferred_start_rxtx_queue_state, 2715 NULL, 2716 }, 2717 }; 2718 2719 /* *** configure port rxq/txq setup *** */ 2720 struct cmd_setup_rxtx_queue { 2721 cmdline_fixed_string_t port; 2722 portid_t portid; 2723 cmdline_fixed_string_t rxtxq; 2724 uint16_t qid; 2725 cmdline_fixed_string_t setup; 2726 }; 2727 2728 /* Common CLI fields for queue setup */ 2729 static cmdline_parse_token_string_t cmd_setup_rxtx_queue_port = 2730 TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port"); 2731 static cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid = 2732 TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, RTE_UINT16); 2733 static cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq = 2734 TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq"); 2735 static cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid = 2736 TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, RTE_UINT16); 2737 static cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup = 2738 TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup"); 2739 2740 static void 2741 cmd_setup_rxtx_queue_parsed( 2742 void *parsed_result, 2743 __rte_unused struct cmdline *cl, 2744 __rte_unused void *data) 2745 { 2746 struct cmd_setup_rxtx_queue *res = parsed_result; 2747 struct rte_port *port; 2748 struct rte_mempool *mp; 2749 unsigned int socket_id; 2750 uint8_t isrx = 0; 2751 int ret; 2752 2753 if (port_id_is_invalid(res->portid, ENABLED_WARN)) 2754 return; 2755 2756 if (res->portid == (portid_t)RTE_PORT_ALL) { 2757 fprintf(stderr, "Invalid port id\n"); 2758 return; 2759 } 2760 2761 if (!strcmp(res->rxtxq, "rxq")) 2762 isrx = 1; 2763 else if (!strcmp(res->rxtxq, "txq")) 2764 isrx = 0; 2765 else { 2766 fprintf(stderr, "Unknown parameter\n"); 2767 return; 2768 } 2769 2770 if (isrx && rx_queue_id_is_invalid(res->qid)) { 2771 fprintf(stderr, "Invalid rx queue\n"); 2772 return; 2773 } else if (!isrx && tx_queue_id_is_invalid(res->qid)) { 2774 fprintf(stderr, "Invalid tx queue\n"); 2775 return; 2776 } 2777 2778 port = &ports[res->portid]; 2779 if (isrx) { 2780 socket_id = rxring_numa[res->portid]; 2781 if (!numa_support || socket_id == NUMA_NO_CONFIG) 2782 socket_id = port->socket_id; 2783 2784 mp = mbuf_pool_find(socket_id, 0); 2785 if (mp == NULL) { 2786 fprintf(stderr, 2787 "Failed to setup RX queue: No mempool allocation on the socket %d\n", 2788 rxring_numa[res->portid]); 2789 return; 2790 } 2791 ret = rx_queue_setup(res->portid, 2792 res->qid, 2793 port->nb_rx_desc[res->qid], 2794 socket_id, 2795 &port->rxq[res->qid].conf, 2796 mp); 2797 if (ret) 2798 fprintf(stderr, "Failed to setup RX queue\n"); 2799 } else { 2800 socket_id = txring_numa[res->portid]; 2801 if (!numa_support || socket_id == NUMA_NO_CONFIG) 2802 socket_id = port->socket_id; 2803 2804 if (port->nb_tx_desc[res->qid] < tx_pkt_nb_segs) { 2805 fprintf(stderr, 2806 "Failed to setup TX queue: not enough descriptors\n"); 2807 return; 2808 } 2809 ret = rte_eth_tx_queue_setup(res->portid, 2810 res->qid, 2811 port->nb_tx_desc[res->qid], 2812 socket_id, 2813 &port->txq[res->qid].conf); 2814 if (ret) 2815 fprintf(stderr, "Failed to setup TX queue\n"); 2816 } 2817 } 2818 2819 static cmdline_parse_inst_t cmd_setup_rxtx_queue = { 2820 .f = cmd_setup_rxtx_queue_parsed, 2821 .data = NULL, 2822 .help_str = "port <port_id> rxq|txq <queue_idx> setup", 2823 .tokens = { 2824 (void *)&cmd_setup_rxtx_queue_port, 2825 (void *)&cmd_setup_rxtx_queue_portid, 2826 (void *)&cmd_setup_rxtx_queue_rxtxq, 2827 (void *)&cmd_setup_rxtx_queue_qid, 2828 (void *)&cmd_setup_rxtx_queue_setup, 2829 NULL, 2830 }, 2831 }; 2832 2833 2834 /* *** Configure RSS RETA *** */ 2835 struct cmd_config_rss_reta { 2836 cmdline_fixed_string_t port; 2837 cmdline_fixed_string_t keyword; 2838 portid_t port_id; 2839 cmdline_fixed_string_t name; 2840 cmdline_fixed_string_t list_name; 2841 cmdline_fixed_string_t list_of_items; 2842 }; 2843 2844 static int 2845 parse_reta_config(const char *str, 2846 struct rte_eth_rss_reta_entry64 *reta_conf, 2847 uint16_t nb_entries) 2848 { 2849 int i; 2850 unsigned size; 2851 uint16_t hash_index, idx, shift; 2852 uint16_t nb_queue; 2853 char s[256]; 2854 const char *p, *p0 = str; 2855 char *end; 2856 enum fieldnames { 2857 FLD_HASH_INDEX = 0, 2858 FLD_QUEUE, 2859 _NUM_FLD 2860 }; 2861 unsigned long int_fld[_NUM_FLD]; 2862 char *str_fld[_NUM_FLD]; 2863 2864 while ((p = strchr(p0,'(')) != NULL) { 2865 ++p; 2866 if((p0 = strchr(p,')')) == NULL) 2867 return -1; 2868 2869 size = p0 - p; 2870 if(size >= sizeof(s)) 2871 return -1; 2872 2873 snprintf(s, sizeof(s), "%.*s", size, p); 2874 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD) 2875 return -1; 2876 for (i = 0; i < _NUM_FLD; i++) { 2877 errno = 0; 2878 int_fld[i] = strtoul(str_fld[i], &end, 0); 2879 if (errno != 0 || end == str_fld[i] || 2880 int_fld[i] > 65535) 2881 return -1; 2882 } 2883 2884 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX]; 2885 nb_queue = (uint16_t)int_fld[FLD_QUEUE]; 2886 2887 if (hash_index >= nb_entries) { 2888 fprintf(stderr, "Invalid RETA hash index=%d\n", 2889 hash_index); 2890 return -1; 2891 } 2892 2893 idx = hash_index / RTE_ETH_RETA_GROUP_SIZE; 2894 shift = hash_index % RTE_ETH_RETA_GROUP_SIZE; 2895 reta_conf[idx].mask |= (1ULL << shift); 2896 reta_conf[idx].reta[shift] = nb_queue; 2897 } 2898 2899 return 0; 2900 } 2901 2902 static void 2903 cmd_set_rss_reta_parsed(void *parsed_result, 2904 __rte_unused struct cmdline *cl, 2905 __rte_unused void *data) 2906 { 2907 int ret; 2908 struct rte_eth_dev_info dev_info; 2909 struct rte_eth_rss_reta_entry64 reta_conf[8]; 2910 struct cmd_config_rss_reta *res = parsed_result; 2911 2912 ret = eth_dev_info_get_print_err(res->port_id, &dev_info); 2913 if (ret != 0) 2914 return; 2915 2916 if (dev_info.reta_size == 0) { 2917 fprintf(stderr, 2918 "Redirection table size is 0 which is invalid for RSS\n"); 2919 return; 2920 } else 2921 printf("The reta size of port %d is %u\n", 2922 res->port_id, dev_info.reta_size); 2923 if (dev_info.reta_size > RTE_ETH_RSS_RETA_SIZE_512) { 2924 fprintf(stderr, 2925 "Currently do not support more than %u entries of redirection table\n", 2926 RTE_ETH_RSS_RETA_SIZE_512); 2927 return; 2928 } 2929 2930 memset(reta_conf, 0, sizeof(reta_conf)); 2931 if (!strcmp(res->list_name, "reta")) { 2932 if (parse_reta_config(res->list_of_items, reta_conf, 2933 dev_info.reta_size)) { 2934 fprintf(stderr, 2935 "Invalid RSS Redirection Table config entered\n"); 2936 return; 2937 } 2938 ret = rte_eth_dev_rss_reta_update(res->port_id, 2939 reta_conf, dev_info.reta_size); 2940 if (ret != 0) 2941 fprintf(stderr, 2942 "Bad redirection table parameter, return code = %d\n", 2943 ret); 2944 } 2945 } 2946 2947 static cmdline_parse_token_string_t cmd_config_rss_reta_port = 2948 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port"); 2949 static cmdline_parse_token_string_t cmd_config_rss_reta_keyword = 2950 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config"); 2951 static cmdline_parse_token_num_t cmd_config_rss_reta_port_id = 2952 TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, RTE_UINT16); 2953 static cmdline_parse_token_string_t cmd_config_rss_reta_name = 2954 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss"); 2955 static cmdline_parse_token_string_t cmd_config_rss_reta_list_name = 2956 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta"); 2957 static cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items = 2958 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items, 2959 NULL); 2960 static cmdline_parse_inst_t cmd_config_rss_reta = { 2961 .f = cmd_set_rss_reta_parsed, 2962 .data = NULL, 2963 .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>", 2964 .tokens = { 2965 (void *)&cmd_config_rss_reta_port, 2966 (void *)&cmd_config_rss_reta_keyword, 2967 (void *)&cmd_config_rss_reta_port_id, 2968 (void *)&cmd_config_rss_reta_name, 2969 (void *)&cmd_config_rss_reta_list_name, 2970 (void *)&cmd_config_rss_reta_list_of_items, 2971 NULL, 2972 }, 2973 }; 2974 2975 /* *** SHOW PORT RETA INFO *** */ 2976 struct cmd_showport_reta { 2977 cmdline_fixed_string_t show; 2978 cmdline_fixed_string_t port; 2979 portid_t port_id; 2980 cmdline_fixed_string_t rss; 2981 cmdline_fixed_string_t reta; 2982 uint16_t size; 2983 cmdline_fixed_string_t list_of_items; 2984 }; 2985 2986 static int 2987 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf, 2988 uint16_t nb_entries, 2989 char *str) 2990 { 2991 uint32_t size; 2992 const char *p, *p0 = str; 2993 char s[256]; 2994 char *end; 2995 char *str_fld[8]; 2996 uint16_t i; 2997 uint16_t num = (nb_entries + RTE_ETH_RETA_GROUP_SIZE - 1) / 2998 RTE_ETH_RETA_GROUP_SIZE; 2999 int ret; 3000 3001 p = strchr(p0, '('); 3002 if (p == NULL) 3003 return -1; 3004 p++; 3005 p0 = strchr(p, ')'); 3006 if (p0 == NULL) 3007 return -1; 3008 size = p0 - p; 3009 if (size >= sizeof(s)) { 3010 fprintf(stderr, 3011 "The string size exceeds the internal buffer size\n"); 3012 return -1; 3013 } 3014 snprintf(s, sizeof(s), "%.*s", size, p); 3015 ret = rte_strsplit(s, sizeof(s), str_fld, num, ','); 3016 if (ret <= 0 || ret != num) { 3017 fprintf(stderr, 3018 "The bits of masks do not match the number of reta entries: %u\n", 3019 num); 3020 return -1; 3021 } 3022 for (i = 0; i < ret; i++) 3023 conf[i].mask = (uint64_t)strtoull(str_fld[i], &end, 0); 3024 3025 return 0; 3026 } 3027 3028 static void 3029 cmd_showport_reta_parsed(void *parsed_result, 3030 __rte_unused struct cmdline *cl, 3031 __rte_unused void *data) 3032 { 3033 struct cmd_showport_reta *res = parsed_result; 3034 struct rte_eth_rss_reta_entry64 reta_conf[8]; 3035 struct rte_eth_dev_info dev_info; 3036 uint16_t max_reta_size; 3037 int ret; 3038 3039 ret = eth_dev_info_get_print_err(res->port_id, &dev_info); 3040 if (ret != 0) 3041 return; 3042 3043 max_reta_size = RTE_MIN(dev_info.reta_size, RTE_ETH_RSS_RETA_SIZE_512); 3044 if (res->size == 0 || res->size > max_reta_size) { 3045 fprintf(stderr, "Invalid redirection table size: %u (1-%u)\n", 3046 res->size, max_reta_size); 3047 return; 3048 } 3049 3050 memset(reta_conf, 0, sizeof(reta_conf)); 3051 if (showport_parse_reta_config(reta_conf, res->size, 3052 res->list_of_items) < 0) { 3053 fprintf(stderr, "Invalid string: %s for reta masks\n", 3054 res->list_of_items); 3055 return; 3056 } 3057 port_rss_reta_info(res->port_id, reta_conf, res->size); 3058 } 3059 3060 static cmdline_parse_token_string_t cmd_showport_reta_show = 3061 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, show, "show"); 3062 static cmdline_parse_token_string_t cmd_showport_reta_port = 3063 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, port, "port"); 3064 static cmdline_parse_token_num_t cmd_showport_reta_port_id = 3065 TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, RTE_UINT16); 3066 static cmdline_parse_token_string_t cmd_showport_reta_rss = 3067 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss"); 3068 static cmdline_parse_token_string_t cmd_showport_reta_reta = 3069 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta"); 3070 static cmdline_parse_token_num_t cmd_showport_reta_size = 3071 TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, RTE_UINT16); 3072 static cmdline_parse_token_string_t cmd_showport_reta_list_of_items = 3073 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, 3074 list_of_items, NULL); 3075 3076 static cmdline_parse_inst_t cmd_showport_reta = { 3077 .f = cmd_showport_reta_parsed, 3078 .data = NULL, 3079 .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>", 3080 .tokens = { 3081 (void *)&cmd_showport_reta_show, 3082 (void *)&cmd_showport_reta_port, 3083 (void *)&cmd_showport_reta_port_id, 3084 (void *)&cmd_showport_reta_rss, 3085 (void *)&cmd_showport_reta_reta, 3086 (void *)&cmd_showport_reta_size, 3087 (void *)&cmd_showport_reta_list_of_items, 3088 NULL, 3089 }, 3090 }; 3091 3092 /* *** Show RSS hash configuration *** */ 3093 struct cmd_showport_rss_hash { 3094 cmdline_fixed_string_t show; 3095 cmdline_fixed_string_t port; 3096 portid_t port_id; 3097 cmdline_fixed_string_t rss_hash; 3098 cmdline_fixed_string_t rss_type; 3099 cmdline_fixed_string_t key; /* optional argument */ 3100 }; 3101 3102 static void cmd_showport_rss_hash_parsed(void *parsed_result, 3103 __rte_unused struct cmdline *cl, 3104 void *show_rss_key) 3105 { 3106 struct cmd_showport_rss_hash *res = parsed_result; 3107 3108 port_rss_hash_conf_show(res->port_id, show_rss_key != NULL); 3109 } 3110 3111 static cmdline_parse_token_string_t cmd_showport_rss_hash_show = 3112 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show"); 3113 static cmdline_parse_token_string_t cmd_showport_rss_hash_port = 3114 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port"); 3115 static cmdline_parse_token_num_t cmd_showport_rss_hash_port_id = 3116 TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, 3117 RTE_UINT16); 3118 static cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash = 3119 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash, 3120 "rss-hash"); 3121 static cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key = 3122 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key"); 3123 3124 static cmdline_parse_inst_t cmd_showport_rss_hash = { 3125 .f = cmd_showport_rss_hash_parsed, 3126 .data = NULL, 3127 .help_str = "show port <port_id> rss-hash", 3128 .tokens = { 3129 (void *)&cmd_showport_rss_hash_show, 3130 (void *)&cmd_showport_rss_hash_port, 3131 (void *)&cmd_showport_rss_hash_port_id, 3132 (void *)&cmd_showport_rss_hash_rss_hash, 3133 NULL, 3134 }, 3135 }; 3136 3137 static cmdline_parse_inst_t cmd_showport_rss_hash_key = { 3138 .f = cmd_showport_rss_hash_parsed, 3139 .data = (void *)1, 3140 .help_str = "show port <port_id> rss-hash key", 3141 .tokens = { 3142 (void *)&cmd_showport_rss_hash_show, 3143 (void *)&cmd_showport_rss_hash_port, 3144 (void *)&cmd_showport_rss_hash_port_id, 3145 (void *)&cmd_showport_rss_hash_rss_hash, 3146 (void *)&cmd_showport_rss_hash_rss_key, 3147 NULL, 3148 }, 3149 }; 3150 3151 /* *** Configure DCB *** */ 3152 struct cmd_config_dcb { 3153 cmdline_fixed_string_t port; 3154 cmdline_fixed_string_t config; 3155 portid_t port_id; 3156 cmdline_fixed_string_t dcb; 3157 cmdline_fixed_string_t vt; 3158 cmdline_fixed_string_t vt_en; 3159 uint8_t num_tcs; 3160 cmdline_fixed_string_t pfc; 3161 cmdline_fixed_string_t pfc_en; 3162 }; 3163 3164 static void 3165 cmd_config_dcb_parsed(void *parsed_result, 3166 __rte_unused struct cmdline *cl, 3167 __rte_unused void *data) 3168 { 3169 struct cmd_config_dcb *res = parsed_result; 3170 struct rte_eth_dcb_info dcb_info; 3171 portid_t port_id = res->port_id; 3172 struct rte_port *port; 3173 uint8_t pfc_en; 3174 int ret; 3175 3176 port = &ports[port_id]; 3177 /** Check if the port is not started **/ 3178 if (port->port_status != RTE_PORT_STOPPED) { 3179 fprintf(stderr, "Please stop port %d first\n", port_id); 3180 return; 3181 } 3182 3183 if ((res->num_tcs != RTE_ETH_4_TCS) && (res->num_tcs != RTE_ETH_8_TCS)) { 3184 fprintf(stderr, 3185 "The invalid number of traffic class, only 4 or 8 allowed.\n"); 3186 return; 3187 } 3188 3189 if (nb_fwd_lcores < res->num_tcs) { 3190 fprintf(stderr, 3191 "nb_cores shouldn't be less than number of TCs.\n"); 3192 return; 3193 } 3194 3195 /* Check whether the port supports the report of DCB info. */ 3196 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info); 3197 if (ret == -ENOTSUP) { 3198 fprintf(stderr, "rte_eth_dev_get_dcb_info not supported.\n"); 3199 return; 3200 } 3201 3202 if (!strncmp(res->pfc_en, "on", 2)) 3203 pfc_en = 1; 3204 else 3205 pfc_en = 0; 3206 3207 /* DCB in VT mode */ 3208 if (!strncmp(res->vt_en, "on", 2)) 3209 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED, 3210 (enum rte_eth_nb_tcs)res->num_tcs, 3211 pfc_en); 3212 else 3213 ret = init_port_dcb_config(port_id, DCB_ENABLED, 3214 (enum rte_eth_nb_tcs)res->num_tcs, 3215 pfc_en); 3216 if (ret != 0) { 3217 fprintf(stderr, "Cannot initialize network ports.\n"); 3218 return; 3219 } 3220 3221 fwd_config_setup(); 3222 3223 cmd_reconfig_device_queue(port_id, 1, 1); 3224 } 3225 3226 static cmdline_parse_token_string_t cmd_config_dcb_port = 3227 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port"); 3228 static cmdline_parse_token_string_t cmd_config_dcb_config = 3229 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config"); 3230 static cmdline_parse_token_num_t cmd_config_dcb_port_id = 3231 TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, RTE_UINT16); 3232 static cmdline_parse_token_string_t cmd_config_dcb_dcb = 3233 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb"); 3234 static cmdline_parse_token_string_t cmd_config_dcb_vt = 3235 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt"); 3236 static cmdline_parse_token_string_t cmd_config_dcb_vt_en = 3237 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off"); 3238 static cmdline_parse_token_num_t cmd_config_dcb_num_tcs = 3239 TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, RTE_UINT8); 3240 static cmdline_parse_token_string_t cmd_config_dcb_pfc = 3241 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc"); 3242 static cmdline_parse_token_string_t cmd_config_dcb_pfc_en = 3243 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off"); 3244 3245 static cmdline_parse_inst_t cmd_config_dcb = { 3246 .f = cmd_config_dcb_parsed, 3247 .data = NULL, 3248 .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off", 3249 .tokens = { 3250 (void *)&cmd_config_dcb_port, 3251 (void *)&cmd_config_dcb_config, 3252 (void *)&cmd_config_dcb_port_id, 3253 (void *)&cmd_config_dcb_dcb, 3254 (void *)&cmd_config_dcb_vt, 3255 (void *)&cmd_config_dcb_vt_en, 3256 (void *)&cmd_config_dcb_num_tcs, 3257 (void *)&cmd_config_dcb_pfc, 3258 (void *)&cmd_config_dcb_pfc_en, 3259 NULL, 3260 }, 3261 }; 3262 3263 /* *** configure number of packets per burst *** */ 3264 struct cmd_config_burst { 3265 cmdline_fixed_string_t port; 3266 cmdline_fixed_string_t keyword; 3267 cmdline_fixed_string_t all; 3268 cmdline_fixed_string_t name; 3269 uint16_t value; 3270 }; 3271 3272 static void 3273 cmd_config_burst_parsed(void *parsed_result, 3274 __rte_unused struct cmdline *cl, 3275 __rte_unused void *data) 3276 { 3277 struct cmd_config_burst *res = parsed_result; 3278 struct rte_eth_dev_info dev_info; 3279 uint16_t rec_nb_pkts; 3280 int ret; 3281 3282 if (!all_ports_stopped()) { 3283 fprintf(stderr, "Please stop all ports first\n"); 3284 return; 3285 } 3286 3287 if (!strcmp(res->name, "burst")) { 3288 if (res->value == 0) { 3289 /* If user gives a value of zero, query the PMD for 3290 * its recommended Rx burst size. Testpmd uses a single 3291 * size for all ports, so assume all ports are the same 3292 * NIC model and use the values from Port 0. 3293 */ 3294 ret = eth_dev_info_get_print_err(0, &dev_info); 3295 if (ret != 0) 3296 return; 3297 3298 rec_nb_pkts = dev_info.default_rxportconf.burst_size; 3299 3300 if (rec_nb_pkts == 0) { 3301 printf("PMD does not recommend a burst size.\n" 3302 "User provided value must be between" 3303 " 1 and %d\n", MAX_PKT_BURST); 3304 return; 3305 } else if (rec_nb_pkts > MAX_PKT_BURST) { 3306 printf("PMD recommended burst size of %d" 3307 " exceeds maximum value of %d\n", 3308 rec_nb_pkts, MAX_PKT_BURST); 3309 return; 3310 } 3311 printf("Using PMD-provided burst value of %d\n", 3312 rec_nb_pkts); 3313 nb_pkt_per_burst = rec_nb_pkts; 3314 } else if (res->value > MAX_PKT_BURST) { 3315 fprintf(stderr, "burst must be >= 1 && <= %d\n", 3316 MAX_PKT_BURST); 3317 return; 3318 } else 3319 nb_pkt_per_burst = res->value; 3320 } else { 3321 fprintf(stderr, "Unknown parameter\n"); 3322 return; 3323 } 3324 3325 init_port_config(); 3326 3327 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 3328 } 3329 3330 static cmdline_parse_token_string_t cmd_config_burst_port = 3331 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port"); 3332 static cmdline_parse_token_string_t cmd_config_burst_keyword = 3333 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config"); 3334 static cmdline_parse_token_string_t cmd_config_burst_all = 3335 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all"); 3336 static cmdline_parse_token_string_t cmd_config_burst_name = 3337 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst"); 3338 static cmdline_parse_token_num_t cmd_config_burst_value = 3339 TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, RTE_UINT16); 3340 3341 static cmdline_parse_inst_t cmd_config_burst = { 3342 .f = cmd_config_burst_parsed, 3343 .data = NULL, 3344 .help_str = "port config all burst <value>", 3345 .tokens = { 3346 (void *)&cmd_config_burst_port, 3347 (void *)&cmd_config_burst_keyword, 3348 (void *)&cmd_config_burst_all, 3349 (void *)&cmd_config_burst_name, 3350 (void *)&cmd_config_burst_value, 3351 NULL, 3352 }, 3353 }; 3354 3355 /* *** configure rx/tx queues *** */ 3356 struct cmd_config_thresh { 3357 cmdline_fixed_string_t port; 3358 cmdline_fixed_string_t keyword; 3359 cmdline_fixed_string_t all; 3360 cmdline_fixed_string_t name; 3361 uint8_t value; 3362 }; 3363 3364 static void 3365 cmd_config_thresh_parsed(void *parsed_result, 3366 __rte_unused struct cmdline *cl, 3367 __rte_unused void *data) 3368 { 3369 struct cmd_config_thresh *res = parsed_result; 3370 3371 if (!all_ports_stopped()) { 3372 fprintf(stderr, "Please stop all ports first\n"); 3373 return; 3374 } 3375 3376 if (!strcmp(res->name, "txpt")) 3377 tx_pthresh = res->value; 3378 else if(!strcmp(res->name, "txht")) 3379 tx_hthresh = res->value; 3380 else if(!strcmp(res->name, "txwt")) 3381 tx_wthresh = res->value; 3382 else if(!strcmp(res->name, "rxpt")) 3383 rx_pthresh = res->value; 3384 else if(!strcmp(res->name, "rxht")) 3385 rx_hthresh = res->value; 3386 else if(!strcmp(res->name, "rxwt")) 3387 rx_wthresh = res->value; 3388 else { 3389 fprintf(stderr, "Unknown parameter\n"); 3390 return; 3391 } 3392 3393 init_port_config(); 3394 3395 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 3396 } 3397 3398 static cmdline_parse_token_string_t cmd_config_thresh_port = 3399 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port"); 3400 static cmdline_parse_token_string_t cmd_config_thresh_keyword = 3401 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config"); 3402 static cmdline_parse_token_string_t cmd_config_thresh_all = 3403 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all"); 3404 static cmdline_parse_token_string_t cmd_config_thresh_name = 3405 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name, 3406 "txpt#txht#txwt#rxpt#rxht#rxwt"); 3407 static cmdline_parse_token_num_t cmd_config_thresh_value = 3408 TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, RTE_UINT8); 3409 3410 static cmdline_parse_inst_t cmd_config_thresh = { 3411 .f = cmd_config_thresh_parsed, 3412 .data = NULL, 3413 .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>", 3414 .tokens = { 3415 (void *)&cmd_config_thresh_port, 3416 (void *)&cmd_config_thresh_keyword, 3417 (void *)&cmd_config_thresh_all, 3418 (void *)&cmd_config_thresh_name, 3419 (void *)&cmd_config_thresh_value, 3420 NULL, 3421 }, 3422 }; 3423 3424 /* *** configure free/rs threshold *** */ 3425 struct cmd_config_threshold { 3426 cmdline_fixed_string_t port; 3427 cmdline_fixed_string_t keyword; 3428 cmdline_fixed_string_t all; 3429 cmdline_fixed_string_t name; 3430 uint16_t value; 3431 }; 3432 3433 static void 3434 cmd_config_threshold_parsed(void *parsed_result, 3435 __rte_unused struct cmdline *cl, 3436 __rte_unused void *data) 3437 { 3438 struct cmd_config_threshold *res = parsed_result; 3439 3440 if (!all_ports_stopped()) { 3441 fprintf(stderr, "Please stop all ports first\n"); 3442 return; 3443 } 3444 3445 if (!strcmp(res->name, "txfreet")) 3446 tx_free_thresh = res->value; 3447 else if (!strcmp(res->name, "txrst")) 3448 tx_rs_thresh = res->value; 3449 else if (!strcmp(res->name, "rxfreet")) 3450 rx_free_thresh = res->value; 3451 else { 3452 fprintf(stderr, "Unknown parameter\n"); 3453 return; 3454 } 3455 3456 init_port_config(); 3457 3458 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 3459 } 3460 3461 static cmdline_parse_token_string_t cmd_config_threshold_port = 3462 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port"); 3463 static cmdline_parse_token_string_t cmd_config_threshold_keyword = 3464 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword, 3465 "config"); 3466 static cmdline_parse_token_string_t cmd_config_threshold_all = 3467 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all"); 3468 static cmdline_parse_token_string_t cmd_config_threshold_name = 3469 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name, 3470 "txfreet#txrst#rxfreet"); 3471 static cmdline_parse_token_num_t cmd_config_threshold_value = 3472 TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, RTE_UINT16); 3473 3474 static cmdline_parse_inst_t cmd_config_threshold = { 3475 .f = cmd_config_threshold_parsed, 3476 .data = NULL, 3477 .help_str = "port config all txfreet|txrst|rxfreet <value>", 3478 .tokens = { 3479 (void *)&cmd_config_threshold_port, 3480 (void *)&cmd_config_threshold_keyword, 3481 (void *)&cmd_config_threshold_all, 3482 (void *)&cmd_config_threshold_name, 3483 (void *)&cmd_config_threshold_value, 3484 NULL, 3485 }, 3486 }; 3487 3488 /* *** stop *** */ 3489 struct cmd_stop_result { 3490 cmdline_fixed_string_t stop; 3491 }; 3492 3493 static void cmd_stop_parsed(__rte_unused void *parsed_result, 3494 __rte_unused struct cmdline *cl, 3495 __rte_unused void *data) 3496 { 3497 stop_packet_forwarding(); 3498 } 3499 3500 static cmdline_parse_token_string_t cmd_stop_stop = 3501 TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop"); 3502 3503 static cmdline_parse_inst_t cmd_stop = { 3504 .f = cmd_stop_parsed, 3505 .data = NULL, 3506 .help_str = "stop: Stop packet forwarding", 3507 .tokens = { 3508 (void *)&cmd_stop_stop, 3509 NULL, 3510 }, 3511 }; 3512 3513 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */ 3514 3515 unsigned int 3516 parse_item_list(const char *str, const char *item_name, unsigned int max_items, 3517 unsigned int *parsed_items, int check_unique_values) 3518 { 3519 unsigned int nb_item; 3520 unsigned int value; 3521 unsigned int i; 3522 unsigned int j; 3523 int value_ok; 3524 char c; 3525 3526 /* 3527 * First parse all items in the list and store their value. 3528 */ 3529 value = 0; 3530 nb_item = 0; 3531 value_ok = 0; 3532 for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) { 3533 c = str[i]; 3534 if ((c >= '0') && (c <= '9')) { 3535 value = (unsigned int) (value * 10 + (c - '0')); 3536 value_ok = 1; 3537 continue; 3538 } 3539 if (c != ',') { 3540 fprintf(stderr, "character %c is not a decimal digit\n", c); 3541 return 0; 3542 } 3543 if (! value_ok) { 3544 fprintf(stderr, "No valid value before comma\n"); 3545 return 0; 3546 } 3547 if (nb_item < max_items) { 3548 parsed_items[nb_item] = value; 3549 value_ok = 0; 3550 value = 0; 3551 } 3552 nb_item++; 3553 } 3554 if (nb_item >= max_items) { 3555 fprintf(stderr, "Number of %s = %u > %u (maximum items)\n", 3556 item_name, nb_item + 1, max_items); 3557 return 0; 3558 } 3559 parsed_items[nb_item++] = value; 3560 if (! check_unique_values) 3561 return nb_item; 3562 3563 /* 3564 * Then, check that all values in the list are different. 3565 * No optimization here... 3566 */ 3567 for (i = 0; i < nb_item; i++) { 3568 for (j = i + 1; j < nb_item; j++) { 3569 if (parsed_items[j] == parsed_items[i]) { 3570 fprintf(stderr, 3571 "duplicated %s %u at index %u and %u\n", 3572 item_name, parsed_items[i], i, j); 3573 return 0; 3574 } 3575 } 3576 } 3577 return nb_item; 3578 } 3579 3580 struct cmd_set_list_result { 3581 cmdline_fixed_string_t cmd_keyword; 3582 cmdline_fixed_string_t list_name; 3583 cmdline_fixed_string_t list_of_items; 3584 }; 3585 3586 static void cmd_set_list_parsed(void *parsed_result, 3587 __rte_unused struct cmdline *cl, 3588 __rte_unused void *data) 3589 { 3590 struct cmd_set_list_result *res; 3591 union { 3592 unsigned int lcorelist[RTE_MAX_LCORE]; 3593 unsigned int portlist[RTE_MAX_ETHPORTS]; 3594 } parsed_items; 3595 unsigned int nb_item; 3596 3597 if (test_done == 0) { 3598 fprintf(stderr, "Please stop forwarding first\n"); 3599 return; 3600 } 3601 3602 res = parsed_result; 3603 if (!strcmp(res->list_name, "corelist")) { 3604 nb_item = parse_item_list(res->list_of_items, "core", 3605 RTE_MAX_LCORE, 3606 parsed_items.lcorelist, 1); 3607 if (nb_item > 0) { 3608 set_fwd_lcores_list(parsed_items.lcorelist, nb_item); 3609 fwd_config_setup(); 3610 } 3611 return; 3612 } 3613 if (!strcmp(res->list_name, "portlist")) { 3614 nb_item = parse_item_list(res->list_of_items, "port", 3615 RTE_MAX_ETHPORTS, 3616 parsed_items.portlist, 1); 3617 if (nb_item > 0) { 3618 set_fwd_ports_list(parsed_items.portlist, nb_item); 3619 fwd_config_setup(); 3620 } 3621 } 3622 } 3623 3624 static cmdline_parse_token_string_t cmd_set_list_keyword = 3625 TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword, 3626 "set"); 3627 static cmdline_parse_token_string_t cmd_set_list_name = 3628 TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name, 3629 "corelist#portlist"); 3630 static cmdline_parse_token_string_t cmd_set_list_of_items = 3631 TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items, 3632 NULL); 3633 3634 static cmdline_parse_inst_t cmd_set_fwd_list = { 3635 .f = cmd_set_list_parsed, 3636 .data = NULL, 3637 .help_str = "set corelist|portlist <list0[,list1]*>", 3638 .tokens = { 3639 (void *)&cmd_set_list_keyword, 3640 (void *)&cmd_set_list_name, 3641 (void *)&cmd_set_list_of_items, 3642 NULL, 3643 }, 3644 }; 3645 3646 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */ 3647 3648 struct cmd_setmask_result { 3649 cmdline_fixed_string_t set; 3650 cmdline_fixed_string_t mask; 3651 uint64_t hexavalue; 3652 }; 3653 3654 static void cmd_set_mask_parsed(void *parsed_result, 3655 __rte_unused struct cmdline *cl, 3656 __rte_unused void *data) 3657 { 3658 struct cmd_setmask_result *res = parsed_result; 3659 3660 if (test_done == 0) { 3661 fprintf(stderr, "Please stop forwarding first\n"); 3662 return; 3663 } 3664 if (!strcmp(res->mask, "coremask")) { 3665 set_fwd_lcores_mask(res->hexavalue); 3666 fwd_config_setup(); 3667 } else if (!strcmp(res->mask, "portmask")) { 3668 set_fwd_ports_mask(res->hexavalue); 3669 fwd_config_setup(); 3670 } 3671 } 3672 3673 static cmdline_parse_token_string_t cmd_setmask_set = 3674 TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set"); 3675 static cmdline_parse_token_string_t cmd_setmask_mask = 3676 TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask, 3677 "coremask#portmask"); 3678 static cmdline_parse_token_num_t cmd_setmask_value = 3679 TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, RTE_UINT64); 3680 3681 static cmdline_parse_inst_t cmd_set_fwd_mask = { 3682 .f = cmd_set_mask_parsed, 3683 .data = NULL, 3684 .help_str = "set coremask|portmask <hexadecimal value>", 3685 .tokens = { 3686 (void *)&cmd_setmask_set, 3687 (void *)&cmd_setmask_mask, 3688 (void *)&cmd_setmask_value, 3689 NULL, 3690 }, 3691 }; 3692 3693 /* 3694 * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION 3695 */ 3696 struct cmd_set_result { 3697 cmdline_fixed_string_t set; 3698 cmdline_fixed_string_t what; 3699 uint16_t value; 3700 }; 3701 3702 static void cmd_set_parsed(void *parsed_result, 3703 __rte_unused struct cmdline *cl, 3704 __rte_unused void *data) 3705 { 3706 struct cmd_set_result *res = parsed_result; 3707 if (!strcmp(res->what, "nbport")) { 3708 set_fwd_ports_number(res->value); 3709 fwd_config_setup(); 3710 } else if (!strcmp(res->what, "nbcore")) { 3711 set_fwd_lcores_number(res->value); 3712 fwd_config_setup(); 3713 } else if (!strcmp(res->what, "burst")) 3714 set_nb_pkt_per_burst(res->value); 3715 else if (!strcmp(res->what, "verbose")) 3716 set_verbose_level(res->value); 3717 } 3718 3719 static cmdline_parse_token_string_t cmd_set_set = 3720 TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set"); 3721 static cmdline_parse_token_string_t cmd_set_what = 3722 TOKEN_STRING_INITIALIZER(struct cmd_set_result, what, 3723 "nbport#nbcore#burst#verbose"); 3724 static cmdline_parse_token_num_t cmd_set_value = 3725 TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, RTE_UINT16); 3726 3727 static cmdline_parse_inst_t cmd_set_numbers = { 3728 .f = cmd_set_parsed, 3729 .data = NULL, 3730 .help_str = "set nbport|nbcore|burst|verbose <value>", 3731 .tokens = { 3732 (void *)&cmd_set_set, 3733 (void *)&cmd_set_what, 3734 (void *)&cmd_set_value, 3735 NULL, 3736 }, 3737 }; 3738 3739 /* *** SET LOG LEVEL CONFIGURATION *** */ 3740 3741 struct cmd_set_log_result { 3742 cmdline_fixed_string_t set; 3743 cmdline_fixed_string_t log; 3744 cmdline_fixed_string_t type; 3745 uint32_t level; 3746 }; 3747 3748 static void 3749 cmd_set_log_parsed(void *parsed_result, 3750 __rte_unused struct cmdline *cl, 3751 __rte_unused void *data) 3752 { 3753 struct cmd_set_log_result *res; 3754 int ret; 3755 3756 res = parsed_result; 3757 if (!strcmp(res->type, "global")) 3758 rte_log_set_global_level(res->level); 3759 else { 3760 ret = rte_log_set_level_regexp(res->type, res->level); 3761 if (ret < 0) 3762 fprintf(stderr, "Unable to set log level\n"); 3763 } 3764 } 3765 3766 static cmdline_parse_token_string_t cmd_set_log_set = 3767 TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set"); 3768 static cmdline_parse_token_string_t cmd_set_log_log = 3769 TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log"); 3770 static cmdline_parse_token_string_t cmd_set_log_type = 3771 TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL); 3772 static cmdline_parse_token_num_t cmd_set_log_level = 3773 TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, RTE_UINT32); 3774 3775 static cmdline_parse_inst_t cmd_set_log = { 3776 .f = cmd_set_log_parsed, 3777 .data = NULL, 3778 .help_str = "set log global|<type> <level>", 3779 .tokens = { 3780 (void *)&cmd_set_log_set, 3781 (void *)&cmd_set_log_log, 3782 (void *)&cmd_set_log_type, 3783 (void *)&cmd_set_log_level, 3784 NULL, 3785 }, 3786 }; 3787 3788 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */ 3789 3790 struct cmd_set_rxoffs_result { 3791 cmdline_fixed_string_t cmd_keyword; 3792 cmdline_fixed_string_t rxoffs; 3793 cmdline_fixed_string_t seg_offsets; 3794 }; 3795 3796 static void 3797 cmd_set_rxoffs_parsed(void *parsed_result, 3798 __rte_unused struct cmdline *cl, 3799 __rte_unused void *data) 3800 { 3801 struct cmd_set_rxoffs_result *res; 3802 unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT]; 3803 unsigned int nb_segs; 3804 3805 res = parsed_result; 3806 nb_segs = parse_item_list(res->seg_offsets, "segment offsets", 3807 MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0); 3808 if (nb_segs > 0) 3809 set_rx_pkt_offsets(seg_offsets, nb_segs); 3810 cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1); 3811 } 3812 3813 static cmdline_parse_token_string_t cmd_set_rxoffs_keyword = 3814 TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result, 3815 cmd_keyword, "set"); 3816 static cmdline_parse_token_string_t cmd_set_rxoffs_name = 3817 TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result, 3818 rxoffs, "rxoffs"); 3819 static cmdline_parse_token_string_t cmd_set_rxoffs_offsets = 3820 TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result, 3821 seg_offsets, NULL); 3822 3823 static cmdline_parse_inst_t cmd_set_rxoffs = { 3824 .f = cmd_set_rxoffs_parsed, 3825 .data = NULL, 3826 .help_str = "set rxoffs <len0[,len1]*>", 3827 .tokens = { 3828 (void *)&cmd_set_rxoffs_keyword, 3829 (void *)&cmd_set_rxoffs_name, 3830 (void *)&cmd_set_rxoffs_offsets, 3831 NULL, 3832 }, 3833 }; 3834 3835 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */ 3836 3837 struct cmd_set_rxpkts_result { 3838 cmdline_fixed_string_t cmd_keyword; 3839 cmdline_fixed_string_t rxpkts; 3840 cmdline_fixed_string_t seg_lengths; 3841 }; 3842 3843 static void 3844 cmd_set_rxpkts_parsed(void *parsed_result, 3845 __rte_unused struct cmdline *cl, 3846 __rte_unused void *data) 3847 { 3848 struct cmd_set_rxpkts_result *res; 3849 unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT]; 3850 unsigned int nb_segs; 3851 3852 res = parsed_result; 3853 nb_segs = parse_item_list(res->seg_lengths, "segment lengths", 3854 MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0); 3855 if (nb_segs > 0) 3856 set_rx_pkt_segments(seg_lengths, nb_segs); 3857 cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1); 3858 } 3859 3860 static cmdline_parse_token_string_t cmd_set_rxpkts_keyword = 3861 TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result, 3862 cmd_keyword, "set"); 3863 static cmdline_parse_token_string_t cmd_set_rxpkts_name = 3864 TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result, 3865 rxpkts, "rxpkts"); 3866 static cmdline_parse_token_string_t cmd_set_rxpkts_lengths = 3867 TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result, 3868 seg_lengths, NULL); 3869 3870 static cmdline_parse_inst_t cmd_set_rxpkts = { 3871 .f = cmd_set_rxpkts_parsed, 3872 .data = NULL, 3873 .help_str = "set rxpkts <len0[,len1]*>", 3874 .tokens = { 3875 (void *)&cmd_set_rxpkts_keyword, 3876 (void *)&cmd_set_rxpkts_name, 3877 (void *)&cmd_set_rxpkts_lengths, 3878 NULL, 3879 }, 3880 }; 3881 3882 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */ 3883 3884 struct cmd_set_txpkts_result { 3885 cmdline_fixed_string_t cmd_keyword; 3886 cmdline_fixed_string_t txpkts; 3887 cmdline_fixed_string_t seg_lengths; 3888 }; 3889 3890 static void 3891 cmd_set_txpkts_parsed(void *parsed_result, 3892 __rte_unused struct cmdline *cl, 3893 __rte_unused void *data) 3894 { 3895 struct cmd_set_txpkts_result *res; 3896 unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT]; 3897 unsigned int nb_segs; 3898 3899 res = parsed_result; 3900 nb_segs = parse_item_list(res->seg_lengths, "segment lengths", 3901 RTE_MAX_SEGS_PER_PKT, seg_lengths, 0); 3902 if (nb_segs > 0) 3903 set_tx_pkt_segments(seg_lengths, nb_segs); 3904 } 3905 3906 static cmdline_parse_token_string_t cmd_set_txpkts_keyword = 3907 TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result, 3908 cmd_keyword, "set"); 3909 static cmdline_parse_token_string_t cmd_set_txpkts_name = 3910 TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result, 3911 txpkts, "txpkts"); 3912 static cmdline_parse_token_string_t cmd_set_txpkts_lengths = 3913 TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result, 3914 seg_lengths, NULL); 3915 3916 static cmdline_parse_inst_t cmd_set_txpkts = { 3917 .f = cmd_set_txpkts_parsed, 3918 .data = NULL, 3919 .help_str = "set txpkts <len0[,len1]*>", 3920 .tokens = { 3921 (void *)&cmd_set_txpkts_keyword, 3922 (void *)&cmd_set_txpkts_name, 3923 (void *)&cmd_set_txpkts_lengths, 3924 NULL, 3925 }, 3926 }; 3927 3928 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */ 3929 3930 struct cmd_set_txsplit_result { 3931 cmdline_fixed_string_t cmd_keyword; 3932 cmdline_fixed_string_t txsplit; 3933 cmdline_fixed_string_t mode; 3934 }; 3935 3936 static void 3937 cmd_set_txsplit_parsed(void *parsed_result, 3938 __rte_unused struct cmdline *cl, 3939 __rte_unused void *data) 3940 { 3941 struct cmd_set_txsplit_result *res; 3942 3943 res = parsed_result; 3944 set_tx_pkt_split(res->mode); 3945 } 3946 3947 static cmdline_parse_token_string_t cmd_set_txsplit_keyword = 3948 TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result, 3949 cmd_keyword, "set"); 3950 static cmdline_parse_token_string_t cmd_set_txsplit_name = 3951 TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result, 3952 txsplit, "txsplit"); 3953 static cmdline_parse_token_string_t cmd_set_txsplit_mode = 3954 TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result, 3955 mode, NULL); 3956 3957 static cmdline_parse_inst_t cmd_set_txsplit = { 3958 .f = cmd_set_txsplit_parsed, 3959 .data = NULL, 3960 .help_str = "set txsplit on|off|rand", 3961 .tokens = { 3962 (void *)&cmd_set_txsplit_keyword, 3963 (void *)&cmd_set_txsplit_name, 3964 (void *)&cmd_set_txsplit_mode, 3965 NULL, 3966 }, 3967 }; 3968 3969 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */ 3970 3971 struct cmd_set_txtimes_result { 3972 cmdline_fixed_string_t cmd_keyword; 3973 cmdline_fixed_string_t txtimes; 3974 cmdline_fixed_string_t tx_times; 3975 }; 3976 3977 static void 3978 cmd_set_txtimes_parsed(void *parsed_result, 3979 __rte_unused struct cmdline *cl, 3980 __rte_unused void *data) 3981 { 3982 struct cmd_set_txtimes_result *res; 3983 unsigned int tx_times[2] = {0, 0}; 3984 unsigned int n_times; 3985 3986 res = parsed_result; 3987 n_times = parse_item_list(res->tx_times, "tx times", 3988 2, tx_times, 0); 3989 if (n_times == 2) 3990 set_tx_pkt_times(tx_times); 3991 } 3992 3993 static cmdline_parse_token_string_t cmd_set_txtimes_keyword = 3994 TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result, 3995 cmd_keyword, "set"); 3996 static cmdline_parse_token_string_t cmd_set_txtimes_name = 3997 TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result, 3998 txtimes, "txtimes"); 3999 static cmdline_parse_token_string_t cmd_set_txtimes_value = 4000 TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result, 4001 tx_times, NULL); 4002 4003 static cmdline_parse_inst_t cmd_set_txtimes = { 4004 .f = cmd_set_txtimes_parsed, 4005 .data = NULL, 4006 .help_str = "set txtimes <inter_burst>,<intra_burst>", 4007 .tokens = { 4008 (void *)&cmd_set_txtimes_keyword, 4009 (void *)&cmd_set_txtimes_name, 4010 (void *)&cmd_set_txtimes_value, 4011 NULL, 4012 }, 4013 }; 4014 4015 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */ 4016 struct cmd_rx_vlan_filter_all_result { 4017 cmdline_fixed_string_t rx_vlan; 4018 cmdline_fixed_string_t what; 4019 cmdline_fixed_string_t all; 4020 portid_t port_id; 4021 }; 4022 4023 static void 4024 cmd_rx_vlan_filter_all_parsed(void *parsed_result, 4025 __rte_unused struct cmdline *cl, 4026 __rte_unused void *data) 4027 { 4028 struct cmd_rx_vlan_filter_all_result *res = parsed_result; 4029 4030 if (!strcmp(res->what, "add")) 4031 rx_vlan_all_filter_set(res->port_id, 1); 4032 else 4033 rx_vlan_all_filter_set(res->port_id, 0); 4034 } 4035 4036 static cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan = 4037 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 4038 rx_vlan, "rx_vlan"); 4039 static cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what = 4040 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 4041 what, "add#rm"); 4042 static cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all = 4043 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 4044 all, "all"); 4045 static cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid = 4046 TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 4047 port_id, RTE_UINT16); 4048 4049 static cmdline_parse_inst_t cmd_rx_vlan_filter_all = { 4050 .f = cmd_rx_vlan_filter_all_parsed, 4051 .data = NULL, 4052 .help_str = "rx_vlan add|rm all <port_id>: " 4053 "Add/Remove all identifiers to/from the set of VLAN " 4054 "identifiers filtered by a port", 4055 .tokens = { 4056 (void *)&cmd_rx_vlan_filter_all_rx_vlan, 4057 (void *)&cmd_rx_vlan_filter_all_what, 4058 (void *)&cmd_rx_vlan_filter_all_all, 4059 (void *)&cmd_rx_vlan_filter_all_portid, 4060 NULL, 4061 }, 4062 }; 4063 4064 /* *** VLAN OFFLOAD SET ON A PORT *** */ 4065 struct cmd_vlan_offload_result { 4066 cmdline_fixed_string_t vlan; 4067 cmdline_fixed_string_t set; 4068 cmdline_fixed_string_t vlan_type; 4069 cmdline_fixed_string_t what; 4070 cmdline_fixed_string_t on; 4071 cmdline_fixed_string_t port_id; 4072 }; 4073 4074 static void 4075 cmd_vlan_offload_parsed(void *parsed_result, 4076 __rte_unused struct cmdline *cl, 4077 __rte_unused void *data) 4078 { 4079 int on; 4080 struct cmd_vlan_offload_result *res = parsed_result; 4081 char *str; 4082 int i, len = 0; 4083 portid_t port_id = 0; 4084 unsigned int tmp; 4085 4086 str = res->port_id; 4087 len = strnlen(str, STR_TOKEN_SIZE); 4088 i = 0; 4089 /* Get port_id first */ 4090 while(i < len){ 4091 if(str[i] == ',') 4092 break; 4093 4094 i++; 4095 } 4096 str[i]='\0'; 4097 tmp = strtoul(str, NULL, 0); 4098 /* If port_id greater that what portid_t can represent, return */ 4099 if(tmp >= RTE_MAX_ETHPORTS) 4100 return; 4101 port_id = (portid_t)tmp; 4102 4103 if (!strcmp(res->on, "on")) 4104 on = 1; 4105 else 4106 on = 0; 4107 4108 if (!strcmp(res->what, "strip")) 4109 rx_vlan_strip_set(port_id, on); 4110 else if(!strcmp(res->what, "stripq")){ 4111 uint16_t queue_id = 0; 4112 4113 /* No queue_id, return */ 4114 if(i + 1 >= len) { 4115 fprintf(stderr, "must specify (port,queue_id)\n"); 4116 return; 4117 } 4118 tmp = strtoul(str + i + 1, NULL, 0); 4119 /* If queue_id greater that what 16-bits can represent, return */ 4120 if(tmp > 0xffff) 4121 return; 4122 4123 queue_id = (uint16_t)tmp; 4124 rx_vlan_strip_set_on_queue(port_id, queue_id, on); 4125 } 4126 else if (!strcmp(res->what, "filter")) 4127 rx_vlan_filter_set(port_id, on); 4128 else if (!strcmp(res->what, "qinq_strip")) 4129 rx_vlan_qinq_strip_set(port_id, on); 4130 else 4131 vlan_extend_set(port_id, on); 4132 4133 return; 4134 } 4135 4136 static cmdline_parse_token_string_t cmd_vlan_offload_vlan = 4137 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 4138 vlan, "vlan"); 4139 static cmdline_parse_token_string_t cmd_vlan_offload_set = 4140 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 4141 set, "set"); 4142 static cmdline_parse_token_string_t cmd_vlan_offload_what = 4143 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 4144 what, "strip#filter#qinq_strip#extend#stripq"); 4145 static cmdline_parse_token_string_t cmd_vlan_offload_on = 4146 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 4147 on, "on#off"); 4148 static cmdline_parse_token_string_t cmd_vlan_offload_portid = 4149 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 4150 port_id, NULL); 4151 4152 static cmdline_parse_inst_t cmd_vlan_offload = { 4153 .f = cmd_vlan_offload_parsed, 4154 .data = NULL, 4155 .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off " 4156 "<port_id[,queue_id]>: " 4157 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides", 4158 .tokens = { 4159 (void *)&cmd_vlan_offload_vlan, 4160 (void *)&cmd_vlan_offload_set, 4161 (void *)&cmd_vlan_offload_what, 4162 (void *)&cmd_vlan_offload_on, 4163 (void *)&cmd_vlan_offload_portid, 4164 NULL, 4165 }, 4166 }; 4167 4168 /* *** VLAN TPID SET ON A PORT *** */ 4169 struct cmd_vlan_tpid_result { 4170 cmdline_fixed_string_t vlan; 4171 cmdline_fixed_string_t set; 4172 cmdline_fixed_string_t vlan_type; 4173 cmdline_fixed_string_t what; 4174 uint16_t tp_id; 4175 portid_t port_id; 4176 }; 4177 4178 static void 4179 cmd_vlan_tpid_parsed(void *parsed_result, 4180 __rte_unused struct cmdline *cl, 4181 __rte_unused void *data) 4182 { 4183 struct cmd_vlan_tpid_result *res = parsed_result; 4184 enum rte_vlan_type vlan_type; 4185 4186 if (!strcmp(res->vlan_type, "inner")) 4187 vlan_type = RTE_ETH_VLAN_TYPE_INNER; 4188 else if (!strcmp(res->vlan_type, "outer")) 4189 vlan_type = RTE_ETH_VLAN_TYPE_OUTER; 4190 else { 4191 fprintf(stderr, "Unknown vlan type\n"); 4192 return; 4193 } 4194 vlan_tpid_set(res->port_id, vlan_type, res->tp_id); 4195 } 4196 4197 static cmdline_parse_token_string_t cmd_vlan_tpid_vlan = 4198 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 4199 vlan, "vlan"); 4200 static cmdline_parse_token_string_t cmd_vlan_tpid_set = 4201 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 4202 set, "set"); 4203 static cmdline_parse_token_string_t cmd_vlan_type = 4204 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 4205 vlan_type, "inner#outer"); 4206 static cmdline_parse_token_string_t cmd_vlan_tpid_what = 4207 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 4208 what, "tpid"); 4209 static cmdline_parse_token_num_t cmd_vlan_tpid_tpid = 4210 TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result, 4211 tp_id, RTE_UINT16); 4212 static cmdline_parse_token_num_t cmd_vlan_tpid_portid = 4213 TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result, 4214 port_id, RTE_UINT16); 4215 4216 static cmdline_parse_inst_t cmd_vlan_tpid = { 4217 .f = cmd_vlan_tpid_parsed, 4218 .data = NULL, 4219 .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: " 4220 "Set the VLAN Ether type", 4221 .tokens = { 4222 (void *)&cmd_vlan_tpid_vlan, 4223 (void *)&cmd_vlan_tpid_set, 4224 (void *)&cmd_vlan_type, 4225 (void *)&cmd_vlan_tpid_what, 4226 (void *)&cmd_vlan_tpid_tpid, 4227 (void *)&cmd_vlan_tpid_portid, 4228 NULL, 4229 }, 4230 }; 4231 4232 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */ 4233 struct cmd_rx_vlan_filter_result { 4234 cmdline_fixed_string_t rx_vlan; 4235 cmdline_fixed_string_t what; 4236 uint16_t vlan_id; 4237 portid_t port_id; 4238 }; 4239 4240 static void 4241 cmd_rx_vlan_filter_parsed(void *parsed_result, 4242 __rte_unused struct cmdline *cl, 4243 __rte_unused void *data) 4244 { 4245 struct cmd_rx_vlan_filter_result *res = parsed_result; 4246 4247 if (!strcmp(res->what, "add")) 4248 rx_vft_set(res->port_id, res->vlan_id, 1); 4249 else 4250 rx_vft_set(res->port_id, res->vlan_id, 0); 4251 } 4252 4253 static cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan = 4254 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result, 4255 rx_vlan, "rx_vlan"); 4256 static cmdline_parse_token_string_t cmd_rx_vlan_filter_what = 4257 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result, 4258 what, "add#rm"); 4259 static cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid = 4260 TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result, 4261 vlan_id, RTE_UINT16); 4262 static cmdline_parse_token_num_t cmd_rx_vlan_filter_portid = 4263 TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result, 4264 port_id, RTE_UINT16); 4265 4266 static cmdline_parse_inst_t cmd_rx_vlan_filter = { 4267 .f = cmd_rx_vlan_filter_parsed, 4268 .data = NULL, 4269 .help_str = "rx_vlan add|rm <vlan_id> <port_id>: " 4270 "Add/Remove a VLAN identifier to/from the set of VLAN " 4271 "identifiers filtered by a port", 4272 .tokens = { 4273 (void *)&cmd_rx_vlan_filter_rx_vlan, 4274 (void *)&cmd_rx_vlan_filter_what, 4275 (void *)&cmd_rx_vlan_filter_vlanid, 4276 (void *)&cmd_rx_vlan_filter_portid, 4277 NULL, 4278 }, 4279 }; 4280 4281 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */ 4282 struct cmd_tx_vlan_set_result { 4283 cmdline_fixed_string_t tx_vlan; 4284 cmdline_fixed_string_t set; 4285 portid_t port_id; 4286 uint16_t vlan_id; 4287 }; 4288 4289 static void 4290 cmd_tx_vlan_set_parsed(void *parsed_result, 4291 __rte_unused struct cmdline *cl, 4292 __rte_unused void *data) 4293 { 4294 struct cmd_tx_vlan_set_result *res = parsed_result; 4295 4296 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 4297 return; 4298 4299 if (!port_is_stopped(res->port_id)) { 4300 fprintf(stderr, "Please stop port %d first\n", res->port_id); 4301 return; 4302 } 4303 4304 tx_vlan_set(res->port_id, res->vlan_id); 4305 4306 cmd_reconfig_device_queue(res->port_id, 1, 1); 4307 } 4308 4309 static cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan = 4310 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result, 4311 tx_vlan, "tx_vlan"); 4312 static cmdline_parse_token_string_t cmd_tx_vlan_set_set = 4313 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result, 4314 set, "set"); 4315 static cmdline_parse_token_num_t cmd_tx_vlan_set_portid = 4316 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result, 4317 port_id, RTE_UINT16); 4318 static cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid = 4319 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result, 4320 vlan_id, RTE_UINT16); 4321 4322 static cmdline_parse_inst_t cmd_tx_vlan_set = { 4323 .f = cmd_tx_vlan_set_parsed, 4324 .data = NULL, 4325 .help_str = "tx_vlan set <port_id> <vlan_id>: " 4326 "Enable hardware insertion of a single VLAN header " 4327 "with a given TAG Identifier in packets sent on a port", 4328 .tokens = { 4329 (void *)&cmd_tx_vlan_set_tx_vlan, 4330 (void *)&cmd_tx_vlan_set_set, 4331 (void *)&cmd_tx_vlan_set_portid, 4332 (void *)&cmd_tx_vlan_set_vlanid, 4333 NULL, 4334 }, 4335 }; 4336 4337 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */ 4338 struct cmd_tx_vlan_set_qinq_result { 4339 cmdline_fixed_string_t tx_vlan; 4340 cmdline_fixed_string_t set; 4341 portid_t port_id; 4342 uint16_t vlan_id; 4343 uint16_t vlan_id_outer; 4344 }; 4345 4346 static void 4347 cmd_tx_vlan_set_qinq_parsed(void *parsed_result, 4348 __rte_unused struct cmdline *cl, 4349 __rte_unused void *data) 4350 { 4351 struct cmd_tx_vlan_set_qinq_result *res = parsed_result; 4352 4353 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 4354 return; 4355 4356 if (!port_is_stopped(res->port_id)) { 4357 fprintf(stderr, "Please stop port %d first\n", res->port_id); 4358 return; 4359 } 4360 4361 tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer); 4362 4363 cmd_reconfig_device_queue(res->port_id, 1, 1); 4364 } 4365 4366 static cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan = 4367 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 4368 tx_vlan, "tx_vlan"); 4369 static cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set = 4370 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 4371 set, "set"); 4372 static cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid = 4373 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 4374 port_id, RTE_UINT16); 4375 static cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid = 4376 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 4377 vlan_id, RTE_UINT16); 4378 static cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer = 4379 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 4380 vlan_id_outer, RTE_UINT16); 4381 4382 static cmdline_parse_inst_t cmd_tx_vlan_set_qinq = { 4383 .f = cmd_tx_vlan_set_qinq_parsed, 4384 .data = NULL, 4385 .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: " 4386 "Enable hardware insertion of double VLAN header " 4387 "with given TAG Identifiers in packets sent on a port", 4388 .tokens = { 4389 (void *)&cmd_tx_vlan_set_qinq_tx_vlan, 4390 (void *)&cmd_tx_vlan_set_qinq_set, 4391 (void *)&cmd_tx_vlan_set_qinq_portid, 4392 (void *)&cmd_tx_vlan_set_qinq_vlanid, 4393 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer, 4394 NULL, 4395 }, 4396 }; 4397 4398 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */ 4399 struct cmd_tx_vlan_set_pvid_result { 4400 cmdline_fixed_string_t tx_vlan; 4401 cmdline_fixed_string_t set; 4402 cmdline_fixed_string_t pvid; 4403 portid_t port_id; 4404 uint16_t vlan_id; 4405 cmdline_fixed_string_t mode; 4406 }; 4407 4408 static void 4409 cmd_tx_vlan_set_pvid_parsed(void *parsed_result, 4410 __rte_unused struct cmdline *cl, 4411 __rte_unused void *data) 4412 { 4413 struct cmd_tx_vlan_set_pvid_result *res = parsed_result; 4414 4415 if (strcmp(res->mode, "on") == 0) 4416 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1); 4417 else 4418 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0); 4419 } 4420 4421 static cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan = 4422 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 4423 tx_vlan, "tx_vlan"); 4424 static cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set = 4425 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 4426 set, "set"); 4427 static cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid = 4428 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 4429 pvid, "pvid"); 4430 static cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id = 4431 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 4432 port_id, RTE_UINT16); 4433 static cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id = 4434 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 4435 vlan_id, RTE_UINT16); 4436 static cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode = 4437 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 4438 mode, "on#off"); 4439 4440 static cmdline_parse_inst_t cmd_tx_vlan_set_pvid = { 4441 .f = cmd_tx_vlan_set_pvid_parsed, 4442 .data = NULL, 4443 .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off", 4444 .tokens = { 4445 (void *)&cmd_tx_vlan_set_pvid_tx_vlan, 4446 (void *)&cmd_tx_vlan_set_pvid_set, 4447 (void *)&cmd_tx_vlan_set_pvid_pvid, 4448 (void *)&cmd_tx_vlan_set_pvid_port_id, 4449 (void *)&cmd_tx_vlan_set_pvid_vlan_id, 4450 (void *)&cmd_tx_vlan_set_pvid_mode, 4451 NULL, 4452 }, 4453 }; 4454 4455 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */ 4456 struct cmd_tx_vlan_reset_result { 4457 cmdline_fixed_string_t tx_vlan; 4458 cmdline_fixed_string_t reset; 4459 portid_t port_id; 4460 }; 4461 4462 static void 4463 cmd_tx_vlan_reset_parsed(void *parsed_result, 4464 __rte_unused struct cmdline *cl, 4465 __rte_unused void *data) 4466 { 4467 struct cmd_tx_vlan_reset_result *res = parsed_result; 4468 4469 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 4470 return; 4471 4472 if (!port_is_stopped(res->port_id)) { 4473 fprintf(stderr, "Please stop port %d first\n", res->port_id); 4474 return; 4475 } 4476 4477 tx_vlan_reset(res->port_id); 4478 4479 cmd_reconfig_device_queue(res->port_id, 1, 1); 4480 } 4481 4482 static cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan = 4483 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result, 4484 tx_vlan, "tx_vlan"); 4485 static cmdline_parse_token_string_t cmd_tx_vlan_reset_reset = 4486 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result, 4487 reset, "reset"); 4488 static cmdline_parse_token_num_t cmd_tx_vlan_reset_portid = 4489 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result, 4490 port_id, RTE_UINT16); 4491 4492 static cmdline_parse_inst_t cmd_tx_vlan_reset = { 4493 .f = cmd_tx_vlan_reset_parsed, 4494 .data = NULL, 4495 .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a " 4496 "VLAN header in packets sent on a port", 4497 .tokens = { 4498 (void *)&cmd_tx_vlan_reset_tx_vlan, 4499 (void *)&cmd_tx_vlan_reset_reset, 4500 (void *)&cmd_tx_vlan_reset_portid, 4501 NULL, 4502 }, 4503 }; 4504 4505 4506 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */ 4507 struct cmd_csum_result { 4508 cmdline_fixed_string_t csum; 4509 cmdline_fixed_string_t mode; 4510 cmdline_fixed_string_t proto; 4511 cmdline_fixed_string_t hwsw; 4512 portid_t port_id; 4513 }; 4514 4515 static void 4516 csum_show(int port_id) 4517 { 4518 struct rte_eth_dev_info dev_info; 4519 uint64_t tx_offloads; 4520 int ret; 4521 4522 tx_offloads = ports[port_id].dev_conf.txmode.offloads; 4523 printf("Parse tunnel is %s\n", 4524 (ports[port_id].parse_tunnel) ? "on" : "off"); 4525 printf("IP checksum offload is %s\n", 4526 (tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw"); 4527 printf("UDP checksum offload is %s\n", 4528 (tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw"); 4529 printf("TCP checksum offload is %s\n", 4530 (tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw"); 4531 printf("SCTP checksum offload is %s\n", 4532 (tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw"); 4533 printf("Outer-Ip checksum offload is %s\n", 4534 (tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw"); 4535 printf("Outer-Udp checksum offload is %s\n", 4536 (tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw"); 4537 4538 /* display warnings if configuration is not supported by the NIC */ 4539 ret = eth_dev_info_get_print_err(port_id, &dev_info); 4540 if (ret != 0) 4541 return; 4542 4543 if ((tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) && 4544 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) == 0) { 4545 fprintf(stderr, 4546 "Warning: hardware IP checksum enabled but not supported by port %d\n", 4547 port_id); 4548 } 4549 if ((tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) && 4550 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) == 0) { 4551 fprintf(stderr, 4552 "Warning: hardware UDP checksum enabled but not supported by port %d\n", 4553 port_id); 4554 } 4555 if ((tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) && 4556 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) == 0) { 4557 fprintf(stderr, 4558 "Warning: hardware TCP checksum enabled but not supported by port %d\n", 4559 port_id); 4560 } 4561 if ((tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) && 4562 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) == 0) { 4563 fprintf(stderr, 4564 "Warning: hardware SCTP checksum enabled but not supported by port %d\n", 4565 port_id); 4566 } 4567 if ((tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) && 4568 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) { 4569 fprintf(stderr, 4570 "Warning: hardware outer IP checksum enabled but not supported by port %d\n", 4571 port_id); 4572 } 4573 if ((tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) && 4574 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) 4575 == 0) { 4576 fprintf(stderr, 4577 "Warning: hardware outer UDP checksum enabled but not supported by port %d\n", 4578 port_id); 4579 } 4580 } 4581 4582 static void 4583 cmd_config_queue_tx_offloads(struct rte_port *port) 4584 { 4585 int k; 4586 4587 /* Apply queue tx offloads configuration */ 4588 for (k = 0; k < port->dev_info.max_tx_queues; k++) 4589 port->txq[k].conf.offloads = 4590 port->dev_conf.txmode.offloads; 4591 } 4592 4593 static void 4594 cmd_csum_parsed(void *parsed_result, 4595 __rte_unused struct cmdline *cl, 4596 __rte_unused void *data) 4597 { 4598 struct cmd_csum_result *res = parsed_result; 4599 int hw = 0; 4600 uint64_t csum_offloads = 0; 4601 struct rte_eth_dev_info dev_info; 4602 int ret; 4603 4604 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) { 4605 fprintf(stderr, "invalid port %d\n", res->port_id); 4606 return; 4607 } 4608 if (!port_is_stopped(res->port_id)) { 4609 fprintf(stderr, "Please stop port %d first\n", res->port_id); 4610 return; 4611 } 4612 4613 ret = eth_dev_info_get_print_err(res->port_id, &dev_info); 4614 if (ret != 0) 4615 return; 4616 4617 if (!strcmp(res->mode, "set")) { 4618 4619 if (!strcmp(res->hwsw, "hw")) 4620 hw = 1; 4621 4622 if (!strcmp(res->proto, "ip")) { 4623 if (hw == 0 || (dev_info.tx_offload_capa & 4624 RTE_ETH_TX_OFFLOAD_IPV4_CKSUM)) { 4625 csum_offloads |= RTE_ETH_TX_OFFLOAD_IPV4_CKSUM; 4626 } else { 4627 fprintf(stderr, 4628 "IP checksum offload is not supported by port %u\n", 4629 res->port_id); 4630 } 4631 } else if (!strcmp(res->proto, "udp")) { 4632 if (hw == 0 || (dev_info.tx_offload_capa & 4633 RTE_ETH_TX_OFFLOAD_UDP_CKSUM)) { 4634 csum_offloads |= RTE_ETH_TX_OFFLOAD_UDP_CKSUM; 4635 } else { 4636 fprintf(stderr, 4637 "UDP checksum offload is not supported by port %u\n", 4638 res->port_id); 4639 } 4640 } else if (!strcmp(res->proto, "tcp")) { 4641 if (hw == 0 || (dev_info.tx_offload_capa & 4642 RTE_ETH_TX_OFFLOAD_TCP_CKSUM)) { 4643 csum_offloads |= RTE_ETH_TX_OFFLOAD_TCP_CKSUM; 4644 } else { 4645 fprintf(stderr, 4646 "TCP checksum offload is not supported by port %u\n", 4647 res->port_id); 4648 } 4649 } else if (!strcmp(res->proto, "sctp")) { 4650 if (hw == 0 || (dev_info.tx_offload_capa & 4651 RTE_ETH_TX_OFFLOAD_SCTP_CKSUM)) { 4652 csum_offloads |= RTE_ETH_TX_OFFLOAD_SCTP_CKSUM; 4653 } else { 4654 fprintf(stderr, 4655 "SCTP checksum offload is not supported by port %u\n", 4656 res->port_id); 4657 } 4658 } else if (!strcmp(res->proto, "outer-ip")) { 4659 if (hw == 0 || (dev_info.tx_offload_capa & 4660 RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM)) { 4661 csum_offloads |= 4662 RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM; 4663 } else { 4664 fprintf(stderr, 4665 "Outer IP checksum offload is not supported by port %u\n", 4666 res->port_id); 4667 } 4668 } else if (!strcmp(res->proto, "outer-udp")) { 4669 if (hw == 0 || (dev_info.tx_offload_capa & 4670 RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)) { 4671 csum_offloads |= 4672 RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM; 4673 } else { 4674 fprintf(stderr, 4675 "Outer UDP checksum offload is not supported by port %u\n", 4676 res->port_id); 4677 } 4678 } 4679 4680 if (hw) { 4681 ports[res->port_id].dev_conf.txmode.offloads |= 4682 csum_offloads; 4683 } else { 4684 ports[res->port_id].dev_conf.txmode.offloads &= 4685 (~csum_offloads); 4686 } 4687 cmd_config_queue_tx_offloads(&ports[res->port_id]); 4688 } 4689 csum_show(res->port_id); 4690 4691 cmd_reconfig_device_queue(res->port_id, 1, 1); 4692 } 4693 4694 static cmdline_parse_token_string_t cmd_csum_csum = 4695 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 4696 csum, "csum"); 4697 static cmdline_parse_token_string_t cmd_csum_mode = 4698 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 4699 mode, "set"); 4700 static cmdline_parse_token_string_t cmd_csum_proto = 4701 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 4702 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp"); 4703 static cmdline_parse_token_string_t cmd_csum_hwsw = 4704 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 4705 hwsw, "hw#sw"); 4706 static cmdline_parse_token_num_t cmd_csum_portid = 4707 TOKEN_NUM_INITIALIZER(struct cmd_csum_result, 4708 port_id, RTE_UINT16); 4709 4710 static cmdline_parse_inst_t cmd_csum_set = { 4711 .f = cmd_csum_parsed, 4712 .data = NULL, 4713 .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: " 4714 "Enable/Disable hardware calculation of L3/L4 checksum when " 4715 "using csum forward engine", 4716 .tokens = { 4717 (void *)&cmd_csum_csum, 4718 (void *)&cmd_csum_mode, 4719 (void *)&cmd_csum_proto, 4720 (void *)&cmd_csum_hwsw, 4721 (void *)&cmd_csum_portid, 4722 NULL, 4723 }, 4724 }; 4725 4726 static cmdline_parse_token_string_t cmd_csum_mode_show = 4727 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 4728 mode, "show"); 4729 4730 static cmdline_parse_inst_t cmd_csum_show = { 4731 .f = cmd_csum_parsed, 4732 .data = NULL, 4733 .help_str = "csum show <port_id>: Show checksum offload configuration", 4734 .tokens = { 4735 (void *)&cmd_csum_csum, 4736 (void *)&cmd_csum_mode_show, 4737 (void *)&cmd_csum_portid, 4738 NULL, 4739 }, 4740 }; 4741 4742 /* Enable/disable tunnel parsing */ 4743 struct cmd_csum_tunnel_result { 4744 cmdline_fixed_string_t csum; 4745 cmdline_fixed_string_t parse; 4746 cmdline_fixed_string_t onoff; 4747 portid_t port_id; 4748 }; 4749 4750 static void 4751 cmd_csum_tunnel_parsed(void *parsed_result, 4752 __rte_unused struct cmdline *cl, 4753 __rte_unused void *data) 4754 { 4755 struct cmd_csum_tunnel_result *res = parsed_result; 4756 4757 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 4758 return; 4759 4760 if (!strcmp(res->onoff, "on")) 4761 ports[res->port_id].parse_tunnel = 1; 4762 else 4763 ports[res->port_id].parse_tunnel = 0; 4764 4765 csum_show(res->port_id); 4766 } 4767 4768 static cmdline_parse_token_string_t cmd_csum_tunnel_csum = 4769 TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result, 4770 csum, "csum"); 4771 static cmdline_parse_token_string_t cmd_csum_tunnel_parse = 4772 TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result, 4773 parse, "parse-tunnel"); 4774 static cmdline_parse_token_string_t cmd_csum_tunnel_onoff = 4775 TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result, 4776 onoff, "on#off"); 4777 static cmdline_parse_token_num_t cmd_csum_tunnel_portid = 4778 TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result, 4779 port_id, RTE_UINT16); 4780 4781 static cmdline_parse_inst_t cmd_csum_tunnel = { 4782 .f = cmd_csum_tunnel_parsed, 4783 .data = NULL, 4784 .help_str = "csum parse-tunnel on|off <port_id>: " 4785 "Enable/Disable parsing of tunnels for csum engine", 4786 .tokens = { 4787 (void *)&cmd_csum_tunnel_csum, 4788 (void *)&cmd_csum_tunnel_parse, 4789 (void *)&cmd_csum_tunnel_onoff, 4790 (void *)&cmd_csum_tunnel_portid, 4791 NULL, 4792 }, 4793 }; 4794 4795 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */ 4796 struct cmd_tso_set_result { 4797 cmdline_fixed_string_t tso; 4798 cmdline_fixed_string_t mode; 4799 uint16_t tso_segsz; 4800 portid_t port_id; 4801 }; 4802 4803 static void 4804 cmd_tso_set_parsed(void *parsed_result, 4805 __rte_unused struct cmdline *cl, 4806 __rte_unused void *data) 4807 { 4808 struct cmd_tso_set_result *res = parsed_result; 4809 struct rte_eth_dev_info dev_info; 4810 int ret; 4811 4812 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 4813 return; 4814 if (!port_is_stopped(res->port_id)) { 4815 fprintf(stderr, "Please stop port %d first\n", res->port_id); 4816 return; 4817 } 4818 4819 if (!strcmp(res->mode, "set")) 4820 ports[res->port_id].tso_segsz = res->tso_segsz; 4821 4822 ret = eth_dev_info_get_print_err(res->port_id, &dev_info); 4823 if (ret != 0) 4824 return; 4825 4826 if ((ports[res->port_id].tso_segsz != 0) && 4827 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) == 0) { 4828 fprintf(stderr, "Error: TSO is not supported by port %d\n", 4829 res->port_id); 4830 return; 4831 } 4832 4833 if (ports[res->port_id].tso_segsz == 0) { 4834 ports[res->port_id].dev_conf.txmode.offloads &= 4835 ~RTE_ETH_TX_OFFLOAD_TCP_TSO; 4836 printf("TSO for non-tunneled packets is disabled\n"); 4837 } else { 4838 ports[res->port_id].dev_conf.txmode.offloads |= 4839 RTE_ETH_TX_OFFLOAD_TCP_TSO; 4840 printf("TSO segment size for non-tunneled packets is %d\n", 4841 ports[res->port_id].tso_segsz); 4842 } 4843 cmd_config_queue_tx_offloads(&ports[res->port_id]); 4844 4845 /* display warnings if configuration is not supported by the NIC */ 4846 ret = eth_dev_info_get_print_err(res->port_id, &dev_info); 4847 if (ret != 0) 4848 return; 4849 4850 if ((ports[res->port_id].tso_segsz != 0) && 4851 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) == 0) { 4852 fprintf(stderr, 4853 "Warning: TSO enabled but not supported by port %d\n", 4854 res->port_id); 4855 } 4856 4857 cmd_reconfig_device_queue(res->port_id, 1, 1); 4858 } 4859 4860 static cmdline_parse_token_string_t cmd_tso_set_tso = 4861 TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result, 4862 tso, "tso"); 4863 static cmdline_parse_token_string_t cmd_tso_set_mode = 4864 TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result, 4865 mode, "set"); 4866 static cmdline_parse_token_num_t cmd_tso_set_tso_segsz = 4867 TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result, 4868 tso_segsz, RTE_UINT16); 4869 static cmdline_parse_token_num_t cmd_tso_set_portid = 4870 TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result, 4871 port_id, RTE_UINT16); 4872 4873 static cmdline_parse_inst_t cmd_tso_set = { 4874 .f = cmd_tso_set_parsed, 4875 .data = NULL, 4876 .help_str = "tso set <tso_segsz> <port_id>: " 4877 "Set TSO segment size of non-tunneled packets for csum engine " 4878 "(0 to disable)", 4879 .tokens = { 4880 (void *)&cmd_tso_set_tso, 4881 (void *)&cmd_tso_set_mode, 4882 (void *)&cmd_tso_set_tso_segsz, 4883 (void *)&cmd_tso_set_portid, 4884 NULL, 4885 }, 4886 }; 4887 4888 static cmdline_parse_token_string_t cmd_tso_show_mode = 4889 TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result, 4890 mode, "show"); 4891 4892 4893 static cmdline_parse_inst_t cmd_tso_show = { 4894 .f = cmd_tso_set_parsed, 4895 .data = NULL, 4896 .help_str = "tso show <port_id>: " 4897 "Show TSO segment size of non-tunneled packets for csum engine", 4898 .tokens = { 4899 (void *)&cmd_tso_set_tso, 4900 (void *)&cmd_tso_show_mode, 4901 (void *)&cmd_tso_set_portid, 4902 NULL, 4903 }, 4904 }; 4905 4906 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */ 4907 struct cmd_tunnel_tso_set_result { 4908 cmdline_fixed_string_t tso; 4909 cmdline_fixed_string_t mode; 4910 uint16_t tso_segsz; 4911 portid_t port_id; 4912 }; 4913 4914 static struct rte_eth_dev_info 4915 check_tunnel_tso_nic_support(portid_t port_id) 4916 { 4917 struct rte_eth_dev_info dev_info; 4918 4919 if (eth_dev_info_get_print_err(port_id, &dev_info) != 0) 4920 return dev_info; 4921 4922 if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO)) 4923 fprintf(stderr, 4924 "Warning: VXLAN TUNNEL TSO not supported therefore not enabled for port %d\n", 4925 port_id); 4926 if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO)) 4927 fprintf(stderr, 4928 "Warning: GRE TUNNEL TSO not supported therefore not enabled for port %d\n", 4929 port_id); 4930 if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO)) 4931 fprintf(stderr, 4932 "Warning: IPIP TUNNEL TSO not supported therefore not enabled for port %d\n", 4933 port_id); 4934 if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO)) 4935 fprintf(stderr, 4936 "Warning: GENEVE TUNNEL TSO not supported therefore not enabled for port %d\n", 4937 port_id); 4938 if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IP_TNL_TSO)) 4939 fprintf(stderr, 4940 "Warning: IP TUNNEL TSO not supported therefore not enabled for port %d\n", 4941 port_id); 4942 if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO)) 4943 fprintf(stderr, 4944 "Warning: UDP TUNNEL TSO not supported therefore not enabled for port %d\n", 4945 port_id); 4946 return dev_info; 4947 } 4948 4949 static void 4950 cmd_tunnel_tso_set_parsed(void *parsed_result, 4951 __rte_unused struct cmdline *cl, 4952 __rte_unused void *data) 4953 { 4954 struct cmd_tunnel_tso_set_result *res = parsed_result; 4955 struct rte_eth_dev_info dev_info; 4956 4957 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 4958 return; 4959 if (!port_is_stopped(res->port_id)) { 4960 fprintf(stderr, "Please stop port %d first\n", res->port_id); 4961 return; 4962 } 4963 4964 if (!strcmp(res->mode, "set")) 4965 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz; 4966 4967 dev_info = check_tunnel_tso_nic_support(res->port_id); 4968 if (ports[res->port_id].tunnel_tso_segsz == 0) { 4969 ports[res->port_id].dev_conf.txmode.offloads &= 4970 ~(RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO | 4971 RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO | 4972 RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO | 4973 RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO | 4974 RTE_ETH_TX_OFFLOAD_IP_TNL_TSO | 4975 RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO); 4976 printf("TSO for tunneled packets is disabled\n"); 4977 } else { 4978 uint64_t tso_offloads = (RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO | 4979 RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO | 4980 RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO | 4981 RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO | 4982 RTE_ETH_TX_OFFLOAD_IP_TNL_TSO | 4983 RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO); 4984 4985 ports[res->port_id].dev_conf.txmode.offloads |= 4986 (tso_offloads & dev_info.tx_offload_capa); 4987 printf("TSO segment size for tunneled packets is %d\n", 4988 ports[res->port_id].tunnel_tso_segsz); 4989 4990 /* Below conditions are needed to make it work: 4991 * (1) tunnel TSO is supported by the NIC; 4992 * (2) "csum parse_tunnel" must be set so that tunneled pkts 4993 * are recognized; 4994 * (3) for tunneled pkts with outer L3 of IPv4, 4995 * "csum set outer-ip" must be set to hw, because after tso, 4996 * total_len of outer IP header is changed, and the checksum 4997 * of outer IP header calculated by sw should be wrong; that 4998 * is not necessary for IPv6 tunneled pkts because there's no 4999 * checksum in IP header anymore. 5000 */ 5001 5002 if (!ports[res->port_id].parse_tunnel) 5003 fprintf(stderr, 5004 "Warning: csum parse_tunnel must be set so that tunneled packets are recognized\n"); 5005 if (!(ports[res->port_id].dev_conf.txmode.offloads & 5006 RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM)) 5007 fprintf(stderr, 5008 "Warning: csum set outer-ip must be set to hw if outer L3 is IPv4; not necessary for IPv6\n"); 5009 } 5010 5011 cmd_config_queue_tx_offloads(&ports[res->port_id]); 5012 cmd_reconfig_device_queue(res->port_id, 1, 1); 5013 } 5014 5015 static cmdline_parse_token_string_t cmd_tunnel_tso_set_tso = 5016 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result, 5017 tso, "tunnel_tso"); 5018 static cmdline_parse_token_string_t cmd_tunnel_tso_set_mode = 5019 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result, 5020 mode, "set"); 5021 static cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz = 5022 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result, 5023 tso_segsz, RTE_UINT16); 5024 static cmdline_parse_token_num_t cmd_tunnel_tso_set_portid = 5025 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result, 5026 port_id, RTE_UINT16); 5027 5028 static cmdline_parse_inst_t cmd_tunnel_tso_set = { 5029 .f = cmd_tunnel_tso_set_parsed, 5030 .data = NULL, 5031 .help_str = "tunnel_tso set <tso_segsz> <port_id>: " 5032 "Set TSO segment size of tunneled packets for csum engine " 5033 "(0 to disable)", 5034 .tokens = { 5035 (void *)&cmd_tunnel_tso_set_tso, 5036 (void *)&cmd_tunnel_tso_set_mode, 5037 (void *)&cmd_tunnel_tso_set_tso_segsz, 5038 (void *)&cmd_tunnel_tso_set_portid, 5039 NULL, 5040 }, 5041 }; 5042 5043 static cmdline_parse_token_string_t cmd_tunnel_tso_show_mode = 5044 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result, 5045 mode, "show"); 5046 5047 5048 static cmdline_parse_inst_t cmd_tunnel_tso_show = { 5049 .f = cmd_tunnel_tso_set_parsed, 5050 .data = NULL, 5051 .help_str = "tunnel_tso show <port_id> " 5052 "Show TSO segment size of tunneled packets for csum engine", 5053 .tokens = { 5054 (void *)&cmd_tunnel_tso_set_tso, 5055 (void *)&cmd_tunnel_tso_show_mode, 5056 (void *)&cmd_tunnel_tso_set_portid, 5057 NULL, 5058 }, 5059 }; 5060 5061 #ifdef RTE_LIB_GRO 5062 /* *** SET GRO FOR A PORT *** */ 5063 struct cmd_gro_enable_result { 5064 cmdline_fixed_string_t cmd_set; 5065 cmdline_fixed_string_t cmd_port; 5066 cmdline_fixed_string_t cmd_keyword; 5067 cmdline_fixed_string_t cmd_onoff; 5068 portid_t cmd_pid; 5069 }; 5070 5071 static void 5072 cmd_gro_enable_parsed(void *parsed_result, 5073 __rte_unused struct cmdline *cl, 5074 __rte_unused void *data) 5075 { 5076 struct cmd_gro_enable_result *res; 5077 5078 res = parsed_result; 5079 if (!strcmp(res->cmd_keyword, "gro")) 5080 setup_gro(res->cmd_onoff, res->cmd_pid); 5081 } 5082 5083 static cmdline_parse_token_string_t cmd_gro_enable_set = 5084 TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result, 5085 cmd_set, "set"); 5086 static cmdline_parse_token_string_t cmd_gro_enable_port = 5087 TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result, 5088 cmd_keyword, "port"); 5089 static cmdline_parse_token_num_t cmd_gro_enable_pid = 5090 TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result, 5091 cmd_pid, RTE_UINT16); 5092 static cmdline_parse_token_string_t cmd_gro_enable_keyword = 5093 TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result, 5094 cmd_keyword, "gro"); 5095 static cmdline_parse_token_string_t cmd_gro_enable_onoff = 5096 TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result, 5097 cmd_onoff, "on#off"); 5098 5099 static cmdline_parse_inst_t cmd_gro_enable = { 5100 .f = cmd_gro_enable_parsed, 5101 .data = NULL, 5102 .help_str = "set port <port_id> gro on|off", 5103 .tokens = { 5104 (void *)&cmd_gro_enable_set, 5105 (void *)&cmd_gro_enable_port, 5106 (void *)&cmd_gro_enable_pid, 5107 (void *)&cmd_gro_enable_keyword, 5108 (void *)&cmd_gro_enable_onoff, 5109 NULL, 5110 }, 5111 }; 5112 5113 /* *** DISPLAY GRO CONFIGURATION *** */ 5114 struct cmd_gro_show_result { 5115 cmdline_fixed_string_t cmd_show; 5116 cmdline_fixed_string_t cmd_port; 5117 cmdline_fixed_string_t cmd_keyword; 5118 portid_t cmd_pid; 5119 }; 5120 5121 static void 5122 cmd_gro_show_parsed(void *parsed_result, 5123 __rte_unused struct cmdline *cl, 5124 __rte_unused void *data) 5125 { 5126 struct cmd_gro_show_result *res; 5127 5128 res = parsed_result; 5129 if (!strcmp(res->cmd_keyword, "gro")) 5130 show_gro(res->cmd_pid); 5131 } 5132 5133 static cmdline_parse_token_string_t cmd_gro_show_show = 5134 TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result, 5135 cmd_show, "show"); 5136 static cmdline_parse_token_string_t cmd_gro_show_port = 5137 TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result, 5138 cmd_port, "port"); 5139 static cmdline_parse_token_num_t cmd_gro_show_pid = 5140 TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result, 5141 cmd_pid, RTE_UINT16); 5142 static cmdline_parse_token_string_t cmd_gro_show_keyword = 5143 TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result, 5144 cmd_keyword, "gro"); 5145 5146 static cmdline_parse_inst_t cmd_gro_show = { 5147 .f = cmd_gro_show_parsed, 5148 .data = NULL, 5149 .help_str = "show port <port_id> gro", 5150 .tokens = { 5151 (void *)&cmd_gro_show_show, 5152 (void *)&cmd_gro_show_port, 5153 (void *)&cmd_gro_show_pid, 5154 (void *)&cmd_gro_show_keyword, 5155 NULL, 5156 }, 5157 }; 5158 5159 /* *** SET FLUSH CYCLES FOR GRO *** */ 5160 struct cmd_gro_flush_result { 5161 cmdline_fixed_string_t cmd_set; 5162 cmdline_fixed_string_t cmd_keyword; 5163 cmdline_fixed_string_t cmd_flush; 5164 uint8_t cmd_cycles; 5165 }; 5166 5167 static void 5168 cmd_gro_flush_parsed(void *parsed_result, 5169 __rte_unused struct cmdline *cl, 5170 __rte_unused void *data) 5171 { 5172 struct cmd_gro_flush_result *res; 5173 5174 res = parsed_result; 5175 if ((!strcmp(res->cmd_keyword, "gro")) && 5176 (!strcmp(res->cmd_flush, "flush"))) 5177 setup_gro_flush_cycles(res->cmd_cycles); 5178 } 5179 5180 static cmdline_parse_token_string_t cmd_gro_flush_set = 5181 TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result, 5182 cmd_set, "set"); 5183 static cmdline_parse_token_string_t cmd_gro_flush_keyword = 5184 TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result, 5185 cmd_keyword, "gro"); 5186 static cmdline_parse_token_string_t cmd_gro_flush_flush = 5187 TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result, 5188 cmd_flush, "flush"); 5189 static cmdline_parse_token_num_t cmd_gro_flush_cycles = 5190 TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result, 5191 cmd_cycles, RTE_UINT8); 5192 5193 static cmdline_parse_inst_t cmd_gro_flush = { 5194 .f = cmd_gro_flush_parsed, 5195 .data = NULL, 5196 .help_str = "set gro flush <cycles>", 5197 .tokens = { 5198 (void *)&cmd_gro_flush_set, 5199 (void *)&cmd_gro_flush_keyword, 5200 (void *)&cmd_gro_flush_flush, 5201 (void *)&cmd_gro_flush_cycles, 5202 NULL, 5203 }, 5204 }; 5205 #endif /* RTE_LIB_GRO */ 5206 5207 #ifdef RTE_LIB_GSO 5208 /* *** ENABLE/DISABLE GSO *** */ 5209 struct cmd_gso_enable_result { 5210 cmdline_fixed_string_t cmd_set; 5211 cmdline_fixed_string_t cmd_port; 5212 cmdline_fixed_string_t cmd_keyword; 5213 cmdline_fixed_string_t cmd_mode; 5214 portid_t cmd_pid; 5215 }; 5216 5217 static void 5218 cmd_gso_enable_parsed(void *parsed_result, 5219 __rte_unused struct cmdline *cl, 5220 __rte_unused void *data) 5221 { 5222 struct cmd_gso_enable_result *res; 5223 5224 res = parsed_result; 5225 if (!strcmp(res->cmd_keyword, "gso")) 5226 setup_gso(res->cmd_mode, res->cmd_pid); 5227 } 5228 5229 static cmdline_parse_token_string_t cmd_gso_enable_set = 5230 TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result, 5231 cmd_set, "set"); 5232 static cmdline_parse_token_string_t cmd_gso_enable_port = 5233 TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result, 5234 cmd_port, "port"); 5235 static cmdline_parse_token_string_t cmd_gso_enable_keyword = 5236 TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result, 5237 cmd_keyword, "gso"); 5238 static cmdline_parse_token_string_t cmd_gso_enable_mode = 5239 TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result, 5240 cmd_mode, "on#off"); 5241 static cmdline_parse_token_num_t cmd_gso_enable_pid = 5242 TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result, 5243 cmd_pid, RTE_UINT16); 5244 5245 static cmdline_parse_inst_t cmd_gso_enable = { 5246 .f = cmd_gso_enable_parsed, 5247 .data = NULL, 5248 .help_str = "set port <port_id> gso on|off", 5249 .tokens = { 5250 (void *)&cmd_gso_enable_set, 5251 (void *)&cmd_gso_enable_port, 5252 (void *)&cmd_gso_enable_pid, 5253 (void *)&cmd_gso_enable_keyword, 5254 (void *)&cmd_gso_enable_mode, 5255 NULL, 5256 }, 5257 }; 5258 5259 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */ 5260 struct cmd_gso_size_result { 5261 cmdline_fixed_string_t cmd_set; 5262 cmdline_fixed_string_t cmd_keyword; 5263 cmdline_fixed_string_t cmd_segsz; 5264 uint16_t cmd_size; 5265 }; 5266 5267 static void 5268 cmd_gso_size_parsed(void *parsed_result, 5269 __rte_unused struct cmdline *cl, 5270 __rte_unused void *data) 5271 { 5272 struct cmd_gso_size_result *res = parsed_result; 5273 5274 if (test_done == 0) { 5275 fprintf(stderr, 5276 "Before setting GSO segsz, please first stop forwarding\n"); 5277 return; 5278 } 5279 5280 if (!strcmp(res->cmd_keyword, "gso") && 5281 !strcmp(res->cmd_segsz, "segsz")) { 5282 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN) 5283 fprintf(stderr, 5284 "gso_size should be larger than %zu. Please input a legal value\n", 5285 RTE_GSO_SEG_SIZE_MIN); 5286 else 5287 gso_max_segment_size = res->cmd_size; 5288 } 5289 } 5290 5291 static cmdline_parse_token_string_t cmd_gso_size_set = 5292 TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result, 5293 cmd_set, "set"); 5294 static cmdline_parse_token_string_t cmd_gso_size_keyword = 5295 TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result, 5296 cmd_keyword, "gso"); 5297 static cmdline_parse_token_string_t cmd_gso_size_segsz = 5298 TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result, 5299 cmd_segsz, "segsz"); 5300 static cmdline_parse_token_num_t cmd_gso_size_size = 5301 TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result, 5302 cmd_size, RTE_UINT16); 5303 5304 static cmdline_parse_inst_t cmd_gso_size = { 5305 .f = cmd_gso_size_parsed, 5306 .data = NULL, 5307 .help_str = "set gso segsz <length>", 5308 .tokens = { 5309 (void *)&cmd_gso_size_set, 5310 (void *)&cmd_gso_size_keyword, 5311 (void *)&cmd_gso_size_segsz, 5312 (void *)&cmd_gso_size_size, 5313 NULL, 5314 }, 5315 }; 5316 5317 /* *** SHOW GSO CONFIGURATION *** */ 5318 struct cmd_gso_show_result { 5319 cmdline_fixed_string_t cmd_show; 5320 cmdline_fixed_string_t cmd_port; 5321 cmdline_fixed_string_t cmd_keyword; 5322 portid_t cmd_pid; 5323 }; 5324 5325 static void 5326 cmd_gso_show_parsed(void *parsed_result, 5327 __rte_unused struct cmdline *cl, 5328 __rte_unused void *data) 5329 { 5330 struct cmd_gso_show_result *res = parsed_result; 5331 5332 if (!rte_eth_dev_is_valid_port(res->cmd_pid)) { 5333 fprintf(stderr, "invalid port id %u\n", res->cmd_pid); 5334 return; 5335 } 5336 if (!strcmp(res->cmd_keyword, "gso")) { 5337 if (gso_ports[res->cmd_pid].enable) { 5338 printf("Max GSO'd packet size: %uB\n" 5339 "Supported GSO types: TCP/IPv4, " 5340 "UDP/IPv4, VxLAN with inner " 5341 "TCP/IPv4 packet, GRE with inner " 5342 "TCP/IPv4 packet\n", 5343 gso_max_segment_size); 5344 } else 5345 printf("GSO is not enabled on Port %u\n", res->cmd_pid); 5346 } 5347 } 5348 5349 static cmdline_parse_token_string_t cmd_gso_show_show = 5350 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result, 5351 cmd_show, "show"); 5352 static cmdline_parse_token_string_t cmd_gso_show_port = 5353 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result, 5354 cmd_port, "port"); 5355 static cmdline_parse_token_string_t cmd_gso_show_keyword = 5356 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result, 5357 cmd_keyword, "gso"); 5358 static cmdline_parse_token_num_t cmd_gso_show_pid = 5359 TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result, 5360 cmd_pid, RTE_UINT16); 5361 5362 static cmdline_parse_inst_t cmd_gso_show = { 5363 .f = cmd_gso_show_parsed, 5364 .data = NULL, 5365 .help_str = "show port <port_id> gso", 5366 .tokens = { 5367 (void *)&cmd_gso_show_show, 5368 (void *)&cmd_gso_show_port, 5369 (void *)&cmd_gso_show_pid, 5370 (void *)&cmd_gso_show_keyword, 5371 NULL, 5372 }, 5373 }; 5374 #endif /* RTE_LIB_GSO */ 5375 5376 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */ 5377 struct cmd_set_flush_rx { 5378 cmdline_fixed_string_t set; 5379 cmdline_fixed_string_t flush_rx; 5380 cmdline_fixed_string_t mode; 5381 }; 5382 5383 static void 5384 cmd_set_flush_rx_parsed(void *parsed_result, 5385 __rte_unused struct cmdline *cl, 5386 __rte_unused void *data) 5387 { 5388 struct cmd_set_flush_rx *res = parsed_result; 5389 5390 if (num_procs > 1 && (strcmp(res->mode, "on") == 0)) { 5391 printf("multi-process doesn't support to flush Rx queues.\n"); 5392 return; 5393 } 5394 5395 no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1); 5396 } 5397 5398 static cmdline_parse_token_string_t cmd_setflushrx_set = 5399 TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx, 5400 set, "set"); 5401 static cmdline_parse_token_string_t cmd_setflushrx_flush_rx = 5402 TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx, 5403 flush_rx, "flush_rx"); 5404 static cmdline_parse_token_string_t cmd_setflushrx_mode = 5405 TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx, 5406 mode, "on#off"); 5407 5408 5409 static cmdline_parse_inst_t cmd_set_flush_rx = { 5410 .f = cmd_set_flush_rx_parsed, 5411 .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams", 5412 .data = NULL, 5413 .tokens = { 5414 (void *)&cmd_setflushrx_set, 5415 (void *)&cmd_setflushrx_flush_rx, 5416 (void *)&cmd_setflushrx_mode, 5417 NULL, 5418 }, 5419 }; 5420 5421 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */ 5422 struct cmd_set_link_check { 5423 cmdline_fixed_string_t set; 5424 cmdline_fixed_string_t link_check; 5425 cmdline_fixed_string_t mode; 5426 }; 5427 5428 static void 5429 cmd_set_link_check_parsed(void *parsed_result, 5430 __rte_unused struct cmdline *cl, 5431 __rte_unused void *data) 5432 { 5433 struct cmd_set_link_check *res = parsed_result; 5434 no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1); 5435 } 5436 5437 static cmdline_parse_token_string_t cmd_setlinkcheck_set = 5438 TOKEN_STRING_INITIALIZER(struct cmd_set_link_check, 5439 set, "set"); 5440 static cmdline_parse_token_string_t cmd_setlinkcheck_link_check = 5441 TOKEN_STRING_INITIALIZER(struct cmd_set_link_check, 5442 link_check, "link_check"); 5443 static cmdline_parse_token_string_t cmd_setlinkcheck_mode = 5444 TOKEN_STRING_INITIALIZER(struct cmd_set_link_check, 5445 mode, "on#off"); 5446 5447 5448 static cmdline_parse_inst_t cmd_set_link_check = { 5449 .f = cmd_set_link_check_parsed, 5450 .help_str = "set link_check on|off: Enable/Disable link status check " 5451 "when starting/stopping a port", 5452 .data = NULL, 5453 .tokens = { 5454 (void *)&cmd_setlinkcheck_set, 5455 (void *)&cmd_setlinkcheck_link_check, 5456 (void *)&cmd_setlinkcheck_mode, 5457 NULL, 5458 }, 5459 }; 5460 5461 /* *** SET NIC BYPASS MODE *** */ 5462 struct cmd_set_bypass_mode_result { 5463 cmdline_fixed_string_t set; 5464 cmdline_fixed_string_t bypass; 5465 cmdline_fixed_string_t mode; 5466 cmdline_fixed_string_t value; 5467 portid_t port_id; 5468 }; 5469 5470 static void 5471 cmd_set_bypass_mode_parsed(void *parsed_result, 5472 __rte_unused struct cmdline *cl, 5473 __rte_unused void *data) 5474 { 5475 struct cmd_set_bypass_mode_result *res = parsed_result; 5476 portid_t port_id = res->port_id; 5477 int32_t rc = -EINVAL; 5478 5479 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS 5480 uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL; 5481 5482 if (!strcmp(res->value, "bypass")) 5483 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS; 5484 else if (!strcmp(res->value, "isolate")) 5485 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE; 5486 else 5487 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL; 5488 5489 /* Set the bypass mode for the relevant port. */ 5490 rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode); 5491 #endif 5492 if (rc != 0) 5493 fprintf(stderr, "\t Failed to set bypass mode for port = %d.\n", 5494 port_id); 5495 } 5496 5497 static cmdline_parse_token_string_t cmd_setbypass_mode_set = 5498 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 5499 set, "set"); 5500 static cmdline_parse_token_string_t cmd_setbypass_mode_bypass = 5501 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 5502 bypass, "bypass"); 5503 static cmdline_parse_token_string_t cmd_setbypass_mode_mode = 5504 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 5505 mode, "mode"); 5506 static cmdline_parse_token_string_t cmd_setbypass_mode_value = 5507 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 5508 value, "normal#bypass#isolate"); 5509 static cmdline_parse_token_num_t cmd_setbypass_mode_port = 5510 TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result, 5511 port_id, RTE_UINT16); 5512 5513 static cmdline_parse_inst_t cmd_set_bypass_mode = { 5514 .f = cmd_set_bypass_mode_parsed, 5515 .help_str = "set bypass mode normal|bypass|isolate <port_id>: " 5516 "Set the NIC bypass mode for port_id", 5517 .data = NULL, 5518 .tokens = { 5519 (void *)&cmd_setbypass_mode_set, 5520 (void *)&cmd_setbypass_mode_bypass, 5521 (void *)&cmd_setbypass_mode_mode, 5522 (void *)&cmd_setbypass_mode_value, 5523 (void *)&cmd_setbypass_mode_port, 5524 NULL, 5525 }, 5526 }; 5527 5528 /* *** SET NIC BYPASS EVENT *** */ 5529 struct cmd_set_bypass_event_result { 5530 cmdline_fixed_string_t set; 5531 cmdline_fixed_string_t bypass; 5532 cmdline_fixed_string_t event; 5533 cmdline_fixed_string_t event_value; 5534 cmdline_fixed_string_t mode; 5535 cmdline_fixed_string_t mode_value; 5536 portid_t port_id; 5537 }; 5538 5539 static void 5540 cmd_set_bypass_event_parsed(void *parsed_result, 5541 __rte_unused struct cmdline *cl, 5542 __rte_unused void *data) 5543 { 5544 int32_t rc = -EINVAL; 5545 struct cmd_set_bypass_event_result *res = parsed_result; 5546 portid_t port_id = res->port_id; 5547 5548 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS 5549 uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE; 5550 uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL; 5551 5552 if (!strcmp(res->event_value, "timeout")) 5553 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT; 5554 else if (!strcmp(res->event_value, "os_on")) 5555 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON; 5556 else if (!strcmp(res->event_value, "os_off")) 5557 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF; 5558 else if (!strcmp(res->event_value, "power_on")) 5559 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON; 5560 else if (!strcmp(res->event_value, "power_off")) 5561 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF; 5562 else 5563 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE; 5564 5565 if (!strcmp(res->mode_value, "bypass")) 5566 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS; 5567 else if (!strcmp(res->mode_value, "isolate")) 5568 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE; 5569 else 5570 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL; 5571 5572 /* Set the watchdog timeout. */ 5573 if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) { 5574 5575 rc = -EINVAL; 5576 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) { 5577 rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id, 5578 bypass_timeout); 5579 } 5580 if (rc != 0) { 5581 fprintf(stderr, 5582 "Failed to set timeout value %u for port %d, errto code: %d.\n", 5583 bypass_timeout, port_id, rc); 5584 } 5585 } 5586 5587 /* Set the bypass event to transition to bypass mode. */ 5588 rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event, 5589 bypass_mode); 5590 #endif 5591 5592 if (rc != 0) 5593 fprintf(stderr, "\t Failed to set bypass event for port = %d.\n", 5594 port_id); 5595 } 5596 5597 static cmdline_parse_token_string_t cmd_setbypass_event_set = 5598 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 5599 set, "set"); 5600 static cmdline_parse_token_string_t cmd_setbypass_event_bypass = 5601 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 5602 bypass, "bypass"); 5603 static cmdline_parse_token_string_t cmd_setbypass_event_event = 5604 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 5605 event, "event"); 5606 static cmdline_parse_token_string_t cmd_setbypass_event_event_value = 5607 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 5608 event_value, "none#timeout#os_off#os_on#power_on#power_off"); 5609 static cmdline_parse_token_string_t cmd_setbypass_event_mode = 5610 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 5611 mode, "mode"); 5612 static cmdline_parse_token_string_t cmd_setbypass_event_mode_value = 5613 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 5614 mode_value, "normal#bypass#isolate"); 5615 static cmdline_parse_token_num_t cmd_setbypass_event_port = 5616 TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result, 5617 port_id, RTE_UINT16); 5618 5619 static cmdline_parse_inst_t cmd_set_bypass_event = { 5620 .f = cmd_set_bypass_event_parsed, 5621 .help_str = "set bypass event none|timeout|os_on|os_off|power_on|" 5622 "power_off mode normal|bypass|isolate <port_id>: " 5623 "Set the NIC bypass event mode for port_id", 5624 .data = NULL, 5625 .tokens = { 5626 (void *)&cmd_setbypass_event_set, 5627 (void *)&cmd_setbypass_event_bypass, 5628 (void *)&cmd_setbypass_event_event, 5629 (void *)&cmd_setbypass_event_event_value, 5630 (void *)&cmd_setbypass_event_mode, 5631 (void *)&cmd_setbypass_event_mode_value, 5632 (void *)&cmd_setbypass_event_port, 5633 NULL, 5634 }, 5635 }; 5636 5637 5638 /* *** SET NIC BYPASS TIMEOUT *** */ 5639 struct cmd_set_bypass_timeout_result { 5640 cmdline_fixed_string_t set; 5641 cmdline_fixed_string_t bypass; 5642 cmdline_fixed_string_t timeout; 5643 cmdline_fixed_string_t value; 5644 }; 5645 5646 static void 5647 cmd_set_bypass_timeout_parsed(void *parsed_result, 5648 __rte_unused struct cmdline *cl, 5649 __rte_unused void *data) 5650 { 5651 __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result; 5652 5653 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS 5654 if (!strcmp(res->value, "1.5")) 5655 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC; 5656 else if (!strcmp(res->value, "2")) 5657 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC; 5658 else if (!strcmp(res->value, "3")) 5659 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC; 5660 else if (!strcmp(res->value, "4")) 5661 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC; 5662 else if (!strcmp(res->value, "8")) 5663 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC; 5664 else if (!strcmp(res->value, "16")) 5665 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC; 5666 else if (!strcmp(res->value, "32")) 5667 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC; 5668 else 5669 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF; 5670 #endif 5671 } 5672 5673 static cmdline_parse_token_string_t cmd_setbypass_timeout_set = 5674 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 5675 set, "set"); 5676 static cmdline_parse_token_string_t cmd_setbypass_timeout_bypass = 5677 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 5678 bypass, "bypass"); 5679 static cmdline_parse_token_string_t cmd_setbypass_timeout_timeout = 5680 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 5681 timeout, "timeout"); 5682 static cmdline_parse_token_string_t cmd_setbypass_timeout_value = 5683 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 5684 value, "0#1.5#2#3#4#8#16#32"); 5685 5686 static cmdline_parse_inst_t cmd_set_bypass_timeout = { 5687 .f = cmd_set_bypass_timeout_parsed, 5688 .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: " 5689 "Set the NIC bypass watchdog timeout in seconds", 5690 .data = NULL, 5691 .tokens = { 5692 (void *)&cmd_setbypass_timeout_set, 5693 (void *)&cmd_setbypass_timeout_bypass, 5694 (void *)&cmd_setbypass_timeout_timeout, 5695 (void *)&cmd_setbypass_timeout_value, 5696 NULL, 5697 }, 5698 }; 5699 5700 /* *** SHOW NIC BYPASS MODE *** */ 5701 struct cmd_show_bypass_config_result { 5702 cmdline_fixed_string_t show; 5703 cmdline_fixed_string_t bypass; 5704 cmdline_fixed_string_t config; 5705 portid_t port_id; 5706 }; 5707 5708 static void 5709 cmd_show_bypass_config_parsed(void *parsed_result, 5710 __rte_unused struct cmdline *cl, 5711 __rte_unused void *data) 5712 { 5713 struct cmd_show_bypass_config_result *res = parsed_result; 5714 portid_t port_id = res->port_id; 5715 int rc = -EINVAL; 5716 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS 5717 uint32_t event_mode; 5718 uint32_t bypass_mode; 5719 uint32_t timeout = bypass_timeout; 5720 unsigned int i; 5721 5722 static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] = 5723 {"off", "1.5", "2", "3", "4", "8", "16", "32"}; 5724 static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] = 5725 {"UNKNOWN", "normal", "bypass", "isolate"}; 5726 static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = { 5727 "NONE", 5728 "OS/board on", 5729 "power supply on", 5730 "OS/board off", 5731 "power supply off", 5732 "timeout"}; 5733 5734 /* Display the bypass mode.*/ 5735 if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) { 5736 fprintf(stderr, "\tFailed to get bypass mode for port = %d\n", 5737 port_id); 5738 return; 5739 } 5740 else { 5741 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode)) 5742 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE; 5743 5744 printf("\tbypass mode = %s\n", modes[bypass_mode]); 5745 } 5746 5747 /* Display the bypass timeout.*/ 5748 if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout)) 5749 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF; 5750 5751 printf("\tbypass timeout = %s\n", timeouts[timeout]); 5752 5753 /* Display the bypass events and associated modes. */ 5754 for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) { 5755 5756 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) { 5757 fprintf(stderr, 5758 "\tFailed to get bypass mode for event = %s\n", 5759 events[i]); 5760 } else { 5761 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode)) 5762 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE; 5763 5764 printf("\tbypass event: %-16s = %s\n", events[i], 5765 modes[event_mode]); 5766 } 5767 } 5768 #endif 5769 if (rc != 0) 5770 fprintf(stderr, 5771 "\tFailed to get bypass configuration for port = %d\n", 5772 port_id); 5773 } 5774 5775 static cmdline_parse_token_string_t cmd_showbypass_config_show = 5776 TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, 5777 show, "show"); 5778 static cmdline_parse_token_string_t cmd_showbypass_config_bypass = 5779 TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, 5780 bypass, "bypass"); 5781 static cmdline_parse_token_string_t cmd_showbypass_config_config = 5782 TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, 5783 config, "config"); 5784 static cmdline_parse_token_num_t cmd_showbypass_config_port = 5785 TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result, 5786 port_id, RTE_UINT16); 5787 5788 static cmdline_parse_inst_t cmd_show_bypass_config = { 5789 .f = cmd_show_bypass_config_parsed, 5790 .help_str = "show bypass config <port_id>: " 5791 "Show the NIC bypass config for port_id", 5792 .data = NULL, 5793 .tokens = { 5794 (void *)&cmd_showbypass_config_show, 5795 (void *)&cmd_showbypass_config_bypass, 5796 (void *)&cmd_showbypass_config_config, 5797 (void *)&cmd_showbypass_config_port, 5798 NULL, 5799 }, 5800 }; 5801 5802 /* *** SET FORWARDING MODE *** */ 5803 struct cmd_set_fwd_mode_result { 5804 cmdline_fixed_string_t set; 5805 cmdline_fixed_string_t fwd; 5806 cmdline_fixed_string_t mode; 5807 }; 5808 5809 static void cmd_set_fwd_mode_parsed(void *parsed_result, 5810 __rte_unused struct cmdline *cl, 5811 __rte_unused void *data) 5812 { 5813 struct cmd_set_fwd_mode_result *res = parsed_result; 5814 5815 retry_enabled = 0; 5816 set_pkt_forwarding_mode(res->mode); 5817 } 5818 5819 static cmdline_parse_token_string_t cmd_setfwd_set = 5820 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set"); 5821 static cmdline_parse_token_string_t cmd_setfwd_fwd = 5822 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd"); 5823 static cmdline_parse_token_string_t cmd_setfwd_mode = 5824 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode, 5825 "" /* defined at init */); 5826 5827 static cmdline_parse_inst_t cmd_set_fwd_mode = { 5828 .f = cmd_set_fwd_mode_parsed, 5829 .data = NULL, 5830 .help_str = NULL, /* defined at init */ 5831 .tokens = { 5832 (void *)&cmd_setfwd_set, 5833 (void *)&cmd_setfwd_fwd, 5834 (void *)&cmd_setfwd_mode, 5835 NULL, 5836 }, 5837 }; 5838 5839 static void cmd_set_fwd_mode_init(void) 5840 { 5841 char *modes, *c; 5842 static char token[128]; 5843 static char help[256]; 5844 cmdline_parse_token_string_t *token_struct; 5845 5846 modes = list_pkt_forwarding_modes(); 5847 snprintf(help, sizeof(help), "set fwd %s: " 5848 "Set packet forwarding mode", modes); 5849 cmd_set_fwd_mode.help_str = help; 5850 5851 /* string token separator is # */ 5852 for (c = token; *modes != '\0'; modes++) 5853 if (*modes == '|') 5854 *c++ = '#'; 5855 else 5856 *c++ = *modes; 5857 token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2]; 5858 token_struct->string_data.str = token; 5859 } 5860 5861 /* *** SET RETRY FORWARDING MODE *** */ 5862 struct cmd_set_fwd_retry_mode_result { 5863 cmdline_fixed_string_t set; 5864 cmdline_fixed_string_t fwd; 5865 cmdline_fixed_string_t mode; 5866 cmdline_fixed_string_t retry; 5867 }; 5868 5869 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result, 5870 __rte_unused struct cmdline *cl, 5871 __rte_unused void *data) 5872 { 5873 struct cmd_set_fwd_retry_mode_result *res = parsed_result; 5874 5875 retry_enabled = 1; 5876 set_pkt_forwarding_mode(res->mode); 5877 } 5878 5879 static cmdline_parse_token_string_t cmd_setfwd_retry_set = 5880 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result, 5881 set, "set"); 5882 static cmdline_parse_token_string_t cmd_setfwd_retry_fwd = 5883 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result, 5884 fwd, "fwd"); 5885 static cmdline_parse_token_string_t cmd_setfwd_retry_mode = 5886 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result, 5887 mode, 5888 "" /* defined at init */); 5889 static cmdline_parse_token_string_t cmd_setfwd_retry_retry = 5890 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result, 5891 retry, "retry"); 5892 5893 static cmdline_parse_inst_t cmd_set_fwd_retry_mode = { 5894 .f = cmd_set_fwd_retry_mode_parsed, 5895 .data = NULL, 5896 .help_str = NULL, /* defined at init */ 5897 .tokens = { 5898 (void *)&cmd_setfwd_retry_set, 5899 (void *)&cmd_setfwd_retry_fwd, 5900 (void *)&cmd_setfwd_retry_mode, 5901 (void *)&cmd_setfwd_retry_retry, 5902 NULL, 5903 }, 5904 }; 5905 5906 static void cmd_set_fwd_retry_mode_init(void) 5907 { 5908 char *modes, *c; 5909 static char token[128]; 5910 static char help[256]; 5911 cmdline_parse_token_string_t *token_struct; 5912 5913 modes = list_pkt_forwarding_retry_modes(); 5914 snprintf(help, sizeof(help), "set fwd %s retry: " 5915 "Set packet forwarding mode with retry", modes); 5916 cmd_set_fwd_retry_mode.help_str = help; 5917 5918 /* string token separator is # */ 5919 for (c = token; *modes != '\0'; modes++) 5920 if (*modes == '|') 5921 *c++ = '#'; 5922 else 5923 *c++ = *modes; 5924 token_struct = (cmdline_parse_token_string_t *) 5925 cmd_set_fwd_retry_mode.tokens[2]; 5926 token_struct->string_data.str = token; 5927 } 5928 5929 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */ 5930 struct cmd_set_burst_tx_retry_result { 5931 cmdline_fixed_string_t set; 5932 cmdline_fixed_string_t burst; 5933 cmdline_fixed_string_t tx; 5934 cmdline_fixed_string_t delay; 5935 uint32_t time; 5936 cmdline_fixed_string_t retry; 5937 uint32_t retry_num; 5938 }; 5939 5940 static void cmd_set_burst_tx_retry_parsed(void *parsed_result, 5941 __rte_unused struct cmdline *cl, 5942 __rte_unused void *data) 5943 { 5944 struct cmd_set_burst_tx_retry_result *res = parsed_result; 5945 5946 if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst") 5947 && !strcmp(res->tx, "tx")) { 5948 if (!strcmp(res->delay, "delay")) 5949 burst_tx_delay_time = res->time; 5950 if (!strcmp(res->retry, "retry")) 5951 burst_tx_retry_num = res->retry_num; 5952 } 5953 5954 } 5955 5956 static cmdline_parse_token_string_t cmd_set_burst_tx_retry_set = 5957 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set"); 5958 static cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst = 5959 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst, 5960 "burst"); 5961 static cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx = 5962 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx"); 5963 static cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay = 5964 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay"); 5965 static cmdline_parse_token_num_t cmd_set_burst_tx_retry_time = 5966 TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, 5967 RTE_UINT32); 5968 static cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry = 5969 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry"); 5970 static cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num = 5971 TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, 5972 RTE_UINT32); 5973 5974 static cmdline_parse_inst_t cmd_set_burst_tx_retry = { 5975 .f = cmd_set_burst_tx_retry_parsed, 5976 .help_str = "set burst tx delay <delay_usec> retry <num_retry>", 5977 .tokens = { 5978 (void *)&cmd_set_burst_tx_retry_set, 5979 (void *)&cmd_set_burst_tx_retry_burst, 5980 (void *)&cmd_set_burst_tx_retry_tx, 5981 (void *)&cmd_set_burst_tx_retry_delay, 5982 (void *)&cmd_set_burst_tx_retry_time, 5983 (void *)&cmd_set_burst_tx_retry_retry, 5984 (void *)&cmd_set_burst_tx_retry_retry_num, 5985 NULL, 5986 }, 5987 }; 5988 5989 /* *** SET PROMISC MODE *** */ 5990 struct cmd_set_promisc_mode_result { 5991 cmdline_fixed_string_t set; 5992 cmdline_fixed_string_t promisc; 5993 cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */ 5994 uint16_t port_num; /* valid if "allports" argument == 0 */ 5995 cmdline_fixed_string_t mode; 5996 }; 5997 5998 static void cmd_set_promisc_mode_parsed(void *parsed_result, 5999 __rte_unused struct cmdline *cl, 6000 void *allports) 6001 { 6002 struct cmd_set_promisc_mode_result *res = parsed_result; 6003 int enable; 6004 portid_t i; 6005 6006 if (!strcmp(res->mode, "on")) 6007 enable = 1; 6008 else 6009 enable = 0; 6010 6011 /* all ports */ 6012 if (allports) { 6013 RTE_ETH_FOREACH_DEV(i) 6014 eth_set_promisc_mode(i, enable); 6015 } else { 6016 eth_set_promisc_mode(res->port_num, enable); 6017 } 6018 } 6019 6020 static cmdline_parse_token_string_t cmd_setpromisc_set = 6021 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set"); 6022 static cmdline_parse_token_string_t cmd_setpromisc_promisc = 6023 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc, 6024 "promisc"); 6025 static cmdline_parse_token_string_t cmd_setpromisc_portall = 6026 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all, 6027 "all"); 6028 static cmdline_parse_token_num_t cmd_setpromisc_portnum = 6029 TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num, 6030 RTE_UINT16); 6031 static cmdline_parse_token_string_t cmd_setpromisc_mode = 6032 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode, 6033 "on#off"); 6034 6035 static cmdline_parse_inst_t cmd_set_promisc_mode_all = { 6036 .f = cmd_set_promisc_mode_parsed, 6037 .data = (void *)1, 6038 .help_str = "set promisc all on|off: Set promisc mode for all ports", 6039 .tokens = { 6040 (void *)&cmd_setpromisc_set, 6041 (void *)&cmd_setpromisc_promisc, 6042 (void *)&cmd_setpromisc_portall, 6043 (void *)&cmd_setpromisc_mode, 6044 NULL, 6045 }, 6046 }; 6047 6048 static cmdline_parse_inst_t cmd_set_promisc_mode_one = { 6049 .f = cmd_set_promisc_mode_parsed, 6050 .data = (void *)0, 6051 .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id", 6052 .tokens = { 6053 (void *)&cmd_setpromisc_set, 6054 (void *)&cmd_setpromisc_promisc, 6055 (void *)&cmd_setpromisc_portnum, 6056 (void *)&cmd_setpromisc_mode, 6057 NULL, 6058 }, 6059 }; 6060 6061 /* *** SET ALLMULTI MODE *** */ 6062 struct cmd_set_allmulti_mode_result { 6063 cmdline_fixed_string_t set; 6064 cmdline_fixed_string_t allmulti; 6065 cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */ 6066 uint16_t port_num; /* valid if "allports" argument == 0 */ 6067 cmdline_fixed_string_t mode; 6068 }; 6069 6070 static void cmd_set_allmulti_mode_parsed(void *parsed_result, 6071 __rte_unused struct cmdline *cl, 6072 void *allports) 6073 { 6074 struct cmd_set_allmulti_mode_result *res = parsed_result; 6075 int enable; 6076 portid_t i; 6077 6078 if (!strcmp(res->mode, "on")) 6079 enable = 1; 6080 else 6081 enable = 0; 6082 6083 /* all ports */ 6084 if (allports) { 6085 RTE_ETH_FOREACH_DEV(i) { 6086 eth_set_allmulticast_mode(i, enable); 6087 } 6088 } 6089 else { 6090 eth_set_allmulticast_mode(res->port_num, enable); 6091 } 6092 } 6093 6094 static cmdline_parse_token_string_t cmd_setallmulti_set = 6095 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set"); 6096 static cmdline_parse_token_string_t cmd_setallmulti_allmulti = 6097 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti, 6098 "allmulti"); 6099 static cmdline_parse_token_string_t cmd_setallmulti_portall = 6100 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all, 6101 "all"); 6102 static cmdline_parse_token_num_t cmd_setallmulti_portnum = 6103 TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num, 6104 RTE_UINT16); 6105 static cmdline_parse_token_string_t cmd_setallmulti_mode = 6106 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode, 6107 "on#off"); 6108 6109 static cmdline_parse_inst_t cmd_set_allmulti_mode_all = { 6110 .f = cmd_set_allmulti_mode_parsed, 6111 .data = (void *)1, 6112 .help_str = "set allmulti all on|off: Set allmulti mode for all ports", 6113 .tokens = { 6114 (void *)&cmd_setallmulti_set, 6115 (void *)&cmd_setallmulti_allmulti, 6116 (void *)&cmd_setallmulti_portall, 6117 (void *)&cmd_setallmulti_mode, 6118 NULL, 6119 }, 6120 }; 6121 6122 static cmdline_parse_inst_t cmd_set_allmulti_mode_one = { 6123 .f = cmd_set_allmulti_mode_parsed, 6124 .data = (void *)0, 6125 .help_str = "set allmulti <port_id> on|off: " 6126 "Set allmulti mode on port_id", 6127 .tokens = { 6128 (void *)&cmd_setallmulti_set, 6129 (void *)&cmd_setallmulti_allmulti, 6130 (void *)&cmd_setallmulti_portnum, 6131 (void *)&cmd_setallmulti_mode, 6132 NULL, 6133 }, 6134 }; 6135 6136 /* *** GET CURRENT ETHERNET LINK FLOW CONTROL *** */ 6137 struct cmd_link_flow_ctrl_show { 6138 cmdline_fixed_string_t show; 6139 cmdline_fixed_string_t port; 6140 portid_t port_id; 6141 cmdline_fixed_string_t flow_ctrl; 6142 }; 6143 6144 static cmdline_parse_token_string_t cmd_lfc_show_show = 6145 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show, 6146 show, "show"); 6147 static cmdline_parse_token_string_t cmd_lfc_show_port = 6148 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show, 6149 port, "port"); 6150 static cmdline_parse_token_num_t cmd_lfc_show_portid = 6151 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_show, 6152 port_id, RTE_UINT16); 6153 static cmdline_parse_token_string_t cmd_lfc_show_flow_ctrl = 6154 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show, 6155 flow_ctrl, "flow_ctrl"); 6156 6157 static void 6158 cmd_link_flow_ctrl_show_parsed(void *parsed_result, 6159 __rte_unused struct cmdline *cl, 6160 __rte_unused void *data) 6161 { 6162 struct cmd_link_flow_ctrl_show *res = parsed_result; 6163 static const char *info_border = "*********************"; 6164 struct rte_eth_fc_conf fc_conf; 6165 bool rx_fc_en = false; 6166 bool tx_fc_en = false; 6167 int ret; 6168 6169 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf); 6170 if (ret != 0) { 6171 fprintf(stderr, 6172 "Failed to get current flow ctrl information: err = %d\n", 6173 ret); 6174 return; 6175 } 6176 6177 if (fc_conf.mode == RTE_ETH_FC_RX_PAUSE || fc_conf.mode == RTE_ETH_FC_FULL) 6178 rx_fc_en = true; 6179 if (fc_conf.mode == RTE_ETH_FC_TX_PAUSE || fc_conf.mode == RTE_ETH_FC_FULL) 6180 tx_fc_en = true; 6181 6182 printf("\n%s Flow control infos for port %-2d %s\n", 6183 info_border, res->port_id, info_border); 6184 printf("FC mode:\n"); 6185 printf(" Rx pause: %s\n", rx_fc_en ? "on" : "off"); 6186 printf(" Tx pause: %s\n", tx_fc_en ? "on" : "off"); 6187 printf("Autoneg: %s\n", fc_conf.autoneg ? "on" : "off"); 6188 printf("Pause time: 0x%x\n", fc_conf.pause_time); 6189 printf("High waterline: 0x%x\n", fc_conf.high_water); 6190 printf("Low waterline: 0x%x\n", fc_conf.low_water); 6191 printf("Send XON: %s\n", fc_conf.send_xon ? "on" : "off"); 6192 printf("Forward MAC control frames: %s\n", 6193 fc_conf.mac_ctrl_frame_fwd ? "on" : "off"); 6194 printf("\n%s************** End ***********%s\n", 6195 info_border, info_border); 6196 } 6197 6198 static cmdline_parse_inst_t cmd_link_flow_control_show = { 6199 .f = cmd_link_flow_ctrl_show_parsed, 6200 .data = NULL, 6201 .help_str = "show port <port_id> flow_ctrl", 6202 .tokens = { 6203 (void *)&cmd_lfc_show_show, 6204 (void *)&cmd_lfc_show_port, 6205 (void *)&cmd_lfc_show_portid, 6206 (void *)&cmd_lfc_show_flow_ctrl, 6207 NULL, 6208 }, 6209 }; 6210 6211 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */ 6212 struct cmd_link_flow_ctrl_set_result { 6213 cmdline_fixed_string_t set; 6214 cmdline_fixed_string_t flow_ctrl; 6215 cmdline_fixed_string_t rx; 6216 cmdline_fixed_string_t rx_lfc_mode; 6217 cmdline_fixed_string_t tx; 6218 cmdline_fixed_string_t tx_lfc_mode; 6219 cmdline_fixed_string_t mac_ctrl_frame_fwd; 6220 cmdline_fixed_string_t mac_ctrl_frame_fwd_mode; 6221 cmdline_fixed_string_t autoneg_str; 6222 cmdline_fixed_string_t autoneg; 6223 cmdline_fixed_string_t hw_str; 6224 uint32_t high_water; 6225 cmdline_fixed_string_t lw_str; 6226 uint32_t low_water; 6227 cmdline_fixed_string_t pt_str; 6228 uint16_t pause_time; 6229 cmdline_fixed_string_t xon_str; 6230 uint16_t send_xon; 6231 portid_t port_id; 6232 }; 6233 6234 static cmdline_parse_token_string_t cmd_lfc_set_set = 6235 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6236 set, "set"); 6237 static cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl = 6238 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6239 flow_ctrl, "flow_ctrl"); 6240 static cmdline_parse_token_string_t cmd_lfc_set_rx = 6241 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6242 rx, "rx"); 6243 static cmdline_parse_token_string_t cmd_lfc_set_rx_mode = 6244 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6245 rx_lfc_mode, "on#off"); 6246 static cmdline_parse_token_string_t cmd_lfc_set_tx = 6247 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6248 tx, "tx"); 6249 static cmdline_parse_token_string_t cmd_lfc_set_tx_mode = 6250 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6251 tx_lfc_mode, "on#off"); 6252 static cmdline_parse_token_string_t cmd_lfc_set_high_water_str = 6253 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6254 hw_str, "high_water"); 6255 static cmdline_parse_token_num_t cmd_lfc_set_high_water = 6256 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6257 high_water, RTE_UINT32); 6258 static cmdline_parse_token_string_t cmd_lfc_set_low_water_str = 6259 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6260 lw_str, "low_water"); 6261 static cmdline_parse_token_num_t cmd_lfc_set_low_water = 6262 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6263 low_water, RTE_UINT32); 6264 static cmdline_parse_token_string_t cmd_lfc_set_pause_time_str = 6265 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6266 pt_str, "pause_time"); 6267 static cmdline_parse_token_num_t cmd_lfc_set_pause_time = 6268 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6269 pause_time, RTE_UINT16); 6270 static cmdline_parse_token_string_t cmd_lfc_set_send_xon_str = 6271 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6272 xon_str, "send_xon"); 6273 static cmdline_parse_token_num_t cmd_lfc_set_send_xon = 6274 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6275 send_xon, RTE_UINT16); 6276 static cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode = 6277 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6278 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd"); 6279 static cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd = 6280 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6281 mac_ctrl_frame_fwd_mode, "on#off"); 6282 static cmdline_parse_token_string_t cmd_lfc_set_autoneg_str = 6283 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6284 autoneg_str, "autoneg"); 6285 static cmdline_parse_token_string_t cmd_lfc_set_autoneg = 6286 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6287 autoneg, "on#off"); 6288 static cmdline_parse_token_num_t cmd_lfc_set_portid = 6289 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6290 port_id, RTE_UINT16); 6291 6292 /* forward declaration */ 6293 static void 6294 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl, 6295 void *data); 6296 6297 static cmdline_parse_inst_t cmd_link_flow_control_set = { 6298 .f = cmd_link_flow_ctrl_set_parsed, 6299 .data = NULL, 6300 .help_str = "set flow_ctrl rx on|off tx on|off <high_water> " 6301 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off " 6302 "autoneg on|off <port_id>: Configure the Ethernet flow control", 6303 .tokens = { 6304 (void *)&cmd_lfc_set_set, 6305 (void *)&cmd_lfc_set_flow_ctrl, 6306 (void *)&cmd_lfc_set_rx, 6307 (void *)&cmd_lfc_set_rx_mode, 6308 (void *)&cmd_lfc_set_tx, 6309 (void *)&cmd_lfc_set_tx_mode, 6310 (void *)&cmd_lfc_set_high_water, 6311 (void *)&cmd_lfc_set_low_water, 6312 (void *)&cmd_lfc_set_pause_time, 6313 (void *)&cmd_lfc_set_send_xon, 6314 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode, 6315 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd, 6316 (void *)&cmd_lfc_set_autoneg_str, 6317 (void *)&cmd_lfc_set_autoneg, 6318 (void *)&cmd_lfc_set_portid, 6319 NULL, 6320 }, 6321 }; 6322 6323 static cmdline_parse_inst_t cmd_link_flow_control_set_rx = { 6324 .f = cmd_link_flow_ctrl_set_parsed, 6325 .data = (void *)&cmd_link_flow_control_set_rx, 6326 .help_str = "set flow_ctrl rx on|off <port_id>: " 6327 "Change rx flow control parameter", 6328 .tokens = { 6329 (void *)&cmd_lfc_set_set, 6330 (void *)&cmd_lfc_set_flow_ctrl, 6331 (void *)&cmd_lfc_set_rx, 6332 (void *)&cmd_lfc_set_rx_mode, 6333 (void *)&cmd_lfc_set_portid, 6334 NULL, 6335 }, 6336 }; 6337 6338 static cmdline_parse_inst_t cmd_link_flow_control_set_tx = { 6339 .f = cmd_link_flow_ctrl_set_parsed, 6340 .data = (void *)&cmd_link_flow_control_set_tx, 6341 .help_str = "set flow_ctrl tx on|off <port_id>: " 6342 "Change tx flow control parameter", 6343 .tokens = { 6344 (void *)&cmd_lfc_set_set, 6345 (void *)&cmd_lfc_set_flow_ctrl, 6346 (void *)&cmd_lfc_set_tx, 6347 (void *)&cmd_lfc_set_tx_mode, 6348 (void *)&cmd_lfc_set_portid, 6349 NULL, 6350 }, 6351 }; 6352 6353 static cmdline_parse_inst_t cmd_link_flow_control_set_hw = { 6354 .f = cmd_link_flow_ctrl_set_parsed, 6355 .data = (void *)&cmd_link_flow_control_set_hw, 6356 .help_str = "set flow_ctrl high_water <value> <port_id>: " 6357 "Change high water flow control parameter", 6358 .tokens = { 6359 (void *)&cmd_lfc_set_set, 6360 (void *)&cmd_lfc_set_flow_ctrl, 6361 (void *)&cmd_lfc_set_high_water_str, 6362 (void *)&cmd_lfc_set_high_water, 6363 (void *)&cmd_lfc_set_portid, 6364 NULL, 6365 }, 6366 }; 6367 6368 static cmdline_parse_inst_t cmd_link_flow_control_set_lw = { 6369 .f = cmd_link_flow_ctrl_set_parsed, 6370 .data = (void *)&cmd_link_flow_control_set_lw, 6371 .help_str = "set flow_ctrl low_water <value> <port_id>: " 6372 "Change low water flow control parameter", 6373 .tokens = { 6374 (void *)&cmd_lfc_set_set, 6375 (void *)&cmd_lfc_set_flow_ctrl, 6376 (void *)&cmd_lfc_set_low_water_str, 6377 (void *)&cmd_lfc_set_low_water, 6378 (void *)&cmd_lfc_set_portid, 6379 NULL, 6380 }, 6381 }; 6382 6383 static cmdline_parse_inst_t cmd_link_flow_control_set_pt = { 6384 .f = cmd_link_flow_ctrl_set_parsed, 6385 .data = (void *)&cmd_link_flow_control_set_pt, 6386 .help_str = "set flow_ctrl pause_time <value> <port_id>: " 6387 "Change pause time flow control parameter", 6388 .tokens = { 6389 (void *)&cmd_lfc_set_set, 6390 (void *)&cmd_lfc_set_flow_ctrl, 6391 (void *)&cmd_lfc_set_pause_time_str, 6392 (void *)&cmd_lfc_set_pause_time, 6393 (void *)&cmd_lfc_set_portid, 6394 NULL, 6395 }, 6396 }; 6397 6398 static cmdline_parse_inst_t cmd_link_flow_control_set_xon = { 6399 .f = cmd_link_flow_ctrl_set_parsed, 6400 .data = (void *)&cmd_link_flow_control_set_xon, 6401 .help_str = "set flow_ctrl send_xon <value> <port_id>: " 6402 "Change send_xon flow control parameter", 6403 .tokens = { 6404 (void *)&cmd_lfc_set_set, 6405 (void *)&cmd_lfc_set_flow_ctrl, 6406 (void *)&cmd_lfc_set_send_xon_str, 6407 (void *)&cmd_lfc_set_send_xon, 6408 (void *)&cmd_lfc_set_portid, 6409 NULL, 6410 }, 6411 }; 6412 6413 static cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = { 6414 .f = cmd_link_flow_ctrl_set_parsed, 6415 .data = (void *)&cmd_link_flow_control_set_macfwd, 6416 .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: " 6417 "Change mac ctrl fwd flow control parameter", 6418 .tokens = { 6419 (void *)&cmd_lfc_set_set, 6420 (void *)&cmd_lfc_set_flow_ctrl, 6421 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode, 6422 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd, 6423 (void *)&cmd_lfc_set_portid, 6424 NULL, 6425 }, 6426 }; 6427 6428 static cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = { 6429 .f = cmd_link_flow_ctrl_set_parsed, 6430 .data = (void *)&cmd_link_flow_control_set_autoneg, 6431 .help_str = "set flow_ctrl autoneg on|off <port_id>: " 6432 "Change autoneg flow control parameter", 6433 .tokens = { 6434 (void *)&cmd_lfc_set_set, 6435 (void *)&cmd_lfc_set_flow_ctrl, 6436 (void *)&cmd_lfc_set_autoneg_str, 6437 (void *)&cmd_lfc_set_autoneg, 6438 (void *)&cmd_lfc_set_portid, 6439 NULL, 6440 }, 6441 }; 6442 6443 static void 6444 cmd_link_flow_ctrl_set_parsed(void *parsed_result, 6445 __rte_unused struct cmdline *cl, 6446 void *data) 6447 { 6448 struct cmd_link_flow_ctrl_set_result *res = parsed_result; 6449 cmdline_parse_inst_t *cmd = data; 6450 struct rte_eth_fc_conf fc_conf; 6451 int rx_fc_en = 0; 6452 int tx_fc_en = 0; 6453 int ret; 6454 6455 /* 6456 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate 6457 * the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx side. 6458 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate 6459 * the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at the Tx side. 6460 */ 6461 static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = { 6462 {RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE}, {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL} 6463 }; 6464 6465 /* Partial command line, retrieve current configuration */ 6466 if (cmd) { 6467 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf); 6468 if (ret != 0) { 6469 fprintf(stderr, 6470 "cannot get current flow ctrl parameters, return code = %d\n", 6471 ret); 6472 return; 6473 } 6474 6475 if ((fc_conf.mode == RTE_ETH_FC_RX_PAUSE) || 6476 (fc_conf.mode == RTE_ETH_FC_FULL)) 6477 rx_fc_en = 1; 6478 if ((fc_conf.mode == RTE_ETH_FC_TX_PAUSE) || 6479 (fc_conf.mode == RTE_ETH_FC_FULL)) 6480 tx_fc_en = 1; 6481 } 6482 6483 if (!cmd || cmd == &cmd_link_flow_control_set_rx) 6484 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0; 6485 6486 if (!cmd || cmd == &cmd_link_flow_control_set_tx) 6487 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0; 6488 6489 fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en]; 6490 6491 if (!cmd || cmd == &cmd_link_flow_control_set_hw) 6492 fc_conf.high_water = res->high_water; 6493 6494 if (!cmd || cmd == &cmd_link_flow_control_set_lw) 6495 fc_conf.low_water = res->low_water; 6496 6497 if (!cmd || cmd == &cmd_link_flow_control_set_pt) 6498 fc_conf.pause_time = res->pause_time; 6499 6500 if (!cmd || cmd == &cmd_link_flow_control_set_xon) 6501 fc_conf.send_xon = res->send_xon; 6502 6503 if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) { 6504 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on")) 6505 fc_conf.mac_ctrl_frame_fwd = 1; 6506 else 6507 fc_conf.mac_ctrl_frame_fwd = 0; 6508 } 6509 6510 if (!cmd || cmd == &cmd_link_flow_control_set_autoneg) 6511 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0; 6512 6513 ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf); 6514 if (ret != 0) 6515 fprintf(stderr, 6516 "bad flow control parameter, return code = %d\n", 6517 ret); 6518 } 6519 6520 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */ 6521 struct cmd_priority_flow_ctrl_set_result { 6522 cmdline_fixed_string_t set; 6523 cmdline_fixed_string_t pfc_ctrl; 6524 cmdline_fixed_string_t rx; 6525 cmdline_fixed_string_t rx_pfc_mode; 6526 cmdline_fixed_string_t tx; 6527 cmdline_fixed_string_t tx_pfc_mode; 6528 uint32_t high_water; 6529 uint32_t low_water; 6530 uint16_t pause_time; 6531 uint8_t priority; 6532 portid_t port_id; 6533 }; 6534 6535 static void 6536 cmd_priority_flow_ctrl_set_parsed(void *parsed_result, 6537 __rte_unused struct cmdline *cl, 6538 __rte_unused void *data) 6539 { 6540 struct cmd_priority_flow_ctrl_set_result *res = parsed_result; 6541 struct rte_eth_pfc_conf pfc_conf; 6542 int rx_fc_enable, tx_fc_enable; 6543 int ret; 6544 6545 /* 6546 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate 6547 * the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx side. 6548 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate 6549 * the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at the Tx side. 6550 */ 6551 static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = { 6552 {RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE}, {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL} 6553 }; 6554 6555 memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf)); 6556 rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0; 6557 tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0; 6558 pfc_conf.fc.mode = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable]; 6559 pfc_conf.fc.high_water = res->high_water; 6560 pfc_conf.fc.low_water = res->low_water; 6561 pfc_conf.fc.pause_time = res->pause_time; 6562 pfc_conf.priority = res->priority; 6563 6564 ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf); 6565 if (ret != 0) 6566 fprintf(stderr, 6567 "bad priority flow control parameter, return code = %d\n", 6568 ret); 6569 } 6570 6571 static cmdline_parse_token_string_t cmd_pfc_set_set = 6572 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6573 set, "set"); 6574 static cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl = 6575 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6576 pfc_ctrl, "pfc_ctrl"); 6577 static cmdline_parse_token_string_t cmd_pfc_set_rx = 6578 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6579 rx, "rx"); 6580 static cmdline_parse_token_string_t cmd_pfc_set_rx_mode = 6581 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6582 rx_pfc_mode, "on#off"); 6583 static cmdline_parse_token_string_t cmd_pfc_set_tx = 6584 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6585 tx, "tx"); 6586 static cmdline_parse_token_string_t cmd_pfc_set_tx_mode = 6587 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6588 tx_pfc_mode, "on#off"); 6589 static cmdline_parse_token_num_t cmd_pfc_set_high_water = 6590 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6591 high_water, RTE_UINT32); 6592 static cmdline_parse_token_num_t cmd_pfc_set_low_water = 6593 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6594 low_water, RTE_UINT32); 6595 static cmdline_parse_token_num_t cmd_pfc_set_pause_time = 6596 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6597 pause_time, RTE_UINT16); 6598 static cmdline_parse_token_num_t cmd_pfc_set_priority = 6599 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6600 priority, RTE_UINT8); 6601 static cmdline_parse_token_num_t cmd_pfc_set_portid = 6602 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6603 port_id, RTE_UINT16); 6604 6605 static cmdline_parse_inst_t cmd_priority_flow_control_set = { 6606 .f = cmd_priority_flow_ctrl_set_parsed, 6607 .data = NULL, 6608 .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> " 6609 "<pause_time> <priority> <port_id>: " 6610 "Configure the Ethernet priority flow control", 6611 .tokens = { 6612 (void *)&cmd_pfc_set_set, 6613 (void *)&cmd_pfc_set_flow_ctrl, 6614 (void *)&cmd_pfc_set_rx, 6615 (void *)&cmd_pfc_set_rx_mode, 6616 (void *)&cmd_pfc_set_tx, 6617 (void *)&cmd_pfc_set_tx_mode, 6618 (void *)&cmd_pfc_set_high_water, 6619 (void *)&cmd_pfc_set_low_water, 6620 (void *)&cmd_pfc_set_pause_time, 6621 (void *)&cmd_pfc_set_priority, 6622 (void *)&cmd_pfc_set_portid, 6623 NULL, 6624 }, 6625 }; 6626 6627 struct cmd_queue_priority_flow_ctrl_set_result { 6628 cmdline_fixed_string_t set; 6629 cmdline_fixed_string_t pfc_queue_ctrl; 6630 portid_t port_id; 6631 cmdline_fixed_string_t rx; 6632 cmdline_fixed_string_t rx_pfc_mode; 6633 uint16_t tx_qid; 6634 uint8_t tx_tc; 6635 cmdline_fixed_string_t tx; 6636 cmdline_fixed_string_t tx_pfc_mode; 6637 uint16_t rx_qid; 6638 uint8_t rx_tc; 6639 uint16_t pause_time; 6640 }; 6641 6642 static void 6643 cmd_queue_priority_flow_ctrl_set_parsed(void *parsed_result, 6644 __rte_unused struct cmdline *cl, 6645 __rte_unused void *data) 6646 { 6647 struct cmd_queue_priority_flow_ctrl_set_result *res = parsed_result; 6648 struct rte_eth_pfc_queue_conf pfc_queue_conf; 6649 int rx_fc_enable, tx_fc_enable; 6650 int ret; 6651 6652 /* 6653 * Rx on/off, flow control is enabled/disabled on RX side. This can 6654 * indicate the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx 6655 * side. Tx on/off, flow control is enabled/disabled on TX side. This 6656 * can indicate the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at 6657 * the Tx side. 6658 */ 6659 static enum rte_eth_fc_mode rx_tx_onoff_2_mode[2][2] = { 6660 {RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE}, 6661 {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL} 6662 }; 6663 6664 memset(&pfc_queue_conf, 0, sizeof(struct rte_eth_pfc_queue_conf)); 6665 rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on", 2)) ? 1 : 0; 6666 tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on", 2)) ? 1 : 0; 6667 pfc_queue_conf.mode = rx_tx_onoff_2_mode[rx_fc_enable][tx_fc_enable]; 6668 pfc_queue_conf.rx_pause.tc = res->tx_tc; 6669 pfc_queue_conf.rx_pause.tx_qid = res->tx_qid; 6670 pfc_queue_conf.tx_pause.tc = res->rx_tc; 6671 pfc_queue_conf.tx_pause.rx_qid = res->rx_qid; 6672 pfc_queue_conf.tx_pause.pause_time = res->pause_time; 6673 6674 ret = rte_eth_dev_priority_flow_ctrl_queue_configure(res->port_id, 6675 &pfc_queue_conf); 6676 if (ret != 0) { 6677 fprintf(stderr, 6678 "bad queue priority flow control parameter, rc = %d\n", 6679 ret); 6680 } 6681 } 6682 6683 static cmdline_parse_token_string_t cmd_q_pfc_set_set = 6684 TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result, 6685 set, "set"); 6686 static cmdline_parse_token_string_t cmd_q_pfc_set_flow_ctrl = 6687 TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result, 6688 pfc_queue_ctrl, "pfc_queue_ctrl"); 6689 static cmdline_parse_token_num_t cmd_q_pfc_set_portid = 6690 TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result, 6691 port_id, RTE_UINT16); 6692 static cmdline_parse_token_string_t cmd_q_pfc_set_rx = 6693 TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result, 6694 rx, "rx"); 6695 static cmdline_parse_token_string_t cmd_q_pfc_set_rx_mode = 6696 TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result, 6697 rx_pfc_mode, "on#off"); 6698 static cmdline_parse_token_num_t cmd_q_pfc_set_tx_qid = 6699 TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result, 6700 tx_qid, RTE_UINT16); 6701 static cmdline_parse_token_num_t cmd_q_pfc_set_tx_tc = 6702 TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result, 6703 tx_tc, RTE_UINT8); 6704 static cmdline_parse_token_string_t cmd_q_pfc_set_tx = 6705 TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result, 6706 tx, "tx"); 6707 static cmdline_parse_token_string_t cmd_q_pfc_set_tx_mode = 6708 TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result, 6709 tx_pfc_mode, "on#off"); 6710 static cmdline_parse_token_num_t cmd_q_pfc_set_rx_qid = 6711 TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result, 6712 rx_qid, RTE_UINT16); 6713 static cmdline_parse_token_num_t cmd_q_pfc_set_rx_tc = 6714 TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result, 6715 rx_tc, RTE_UINT8); 6716 static cmdline_parse_token_num_t cmd_q_pfc_set_pause_time = 6717 TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result, 6718 pause_time, RTE_UINT16); 6719 6720 static cmdline_parse_inst_t cmd_queue_priority_flow_control_set = { 6721 .f = cmd_queue_priority_flow_ctrl_set_parsed, 6722 .data = NULL, 6723 .help_str = "set pfc_queue_ctrl <port_id> rx <on|off> <tx_qid> <tx_tc> " 6724 "tx <on|off> <rx_qid> <rx_tc> <pause_time>: " 6725 "Configure the Ethernet queue priority flow control", 6726 .tokens = { 6727 (void *)&cmd_q_pfc_set_set, 6728 (void *)&cmd_q_pfc_set_flow_ctrl, 6729 (void *)&cmd_q_pfc_set_portid, 6730 (void *)&cmd_q_pfc_set_rx, 6731 (void *)&cmd_q_pfc_set_rx_mode, 6732 (void *)&cmd_q_pfc_set_tx_qid, 6733 (void *)&cmd_q_pfc_set_tx_tc, 6734 (void *)&cmd_q_pfc_set_tx, 6735 (void *)&cmd_q_pfc_set_tx_mode, 6736 (void *)&cmd_q_pfc_set_rx_qid, 6737 (void *)&cmd_q_pfc_set_rx_tc, 6738 (void *)&cmd_q_pfc_set_pause_time, 6739 NULL, 6740 }, 6741 }; 6742 6743 /* *** RESET CONFIGURATION *** */ 6744 struct cmd_reset_result { 6745 cmdline_fixed_string_t reset; 6746 cmdline_fixed_string_t def; 6747 }; 6748 6749 static void cmd_reset_parsed(__rte_unused void *parsed_result, 6750 struct cmdline *cl, 6751 __rte_unused void *data) 6752 { 6753 cmdline_printf(cl, "Reset to default forwarding configuration...\n"); 6754 set_def_fwd_config(); 6755 } 6756 6757 static cmdline_parse_token_string_t cmd_reset_set = 6758 TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set"); 6759 static cmdline_parse_token_string_t cmd_reset_def = 6760 TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def, 6761 "default"); 6762 6763 static cmdline_parse_inst_t cmd_reset = { 6764 .f = cmd_reset_parsed, 6765 .data = NULL, 6766 .help_str = "set default: Reset default forwarding configuration", 6767 .tokens = { 6768 (void *)&cmd_reset_set, 6769 (void *)&cmd_reset_def, 6770 NULL, 6771 }, 6772 }; 6773 6774 /* *** START FORWARDING *** */ 6775 struct cmd_start_result { 6776 cmdline_fixed_string_t start; 6777 }; 6778 6779 static cmdline_parse_token_string_t cmd_start_start = 6780 TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start"); 6781 6782 static void cmd_start_parsed(__rte_unused void *parsed_result, 6783 __rte_unused struct cmdline *cl, 6784 __rte_unused void *data) 6785 { 6786 start_packet_forwarding(0); 6787 } 6788 6789 static cmdline_parse_inst_t cmd_start = { 6790 .f = cmd_start_parsed, 6791 .data = NULL, 6792 .help_str = "start: Start packet forwarding", 6793 .tokens = { 6794 (void *)&cmd_start_start, 6795 NULL, 6796 }, 6797 }; 6798 6799 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */ 6800 struct cmd_start_tx_first_result { 6801 cmdline_fixed_string_t start; 6802 cmdline_fixed_string_t tx_first; 6803 }; 6804 6805 static void 6806 cmd_start_tx_first_parsed(__rte_unused void *parsed_result, 6807 __rte_unused struct cmdline *cl, 6808 __rte_unused void *data) 6809 { 6810 start_packet_forwarding(1); 6811 } 6812 6813 static cmdline_parse_token_string_t cmd_start_tx_first_start = 6814 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start, 6815 "start"); 6816 static cmdline_parse_token_string_t cmd_start_tx_first_tx_first = 6817 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, 6818 tx_first, "tx_first"); 6819 6820 static cmdline_parse_inst_t cmd_start_tx_first = { 6821 .f = cmd_start_tx_first_parsed, 6822 .data = NULL, 6823 .help_str = "start tx_first: Start packet forwarding, " 6824 "after sending 1 burst of packets", 6825 .tokens = { 6826 (void *)&cmd_start_tx_first_start, 6827 (void *)&cmd_start_tx_first_tx_first, 6828 NULL, 6829 }, 6830 }; 6831 6832 /* *** START FORWARDING WITH N TX BURST FIRST *** */ 6833 struct cmd_start_tx_first_n_result { 6834 cmdline_fixed_string_t start; 6835 cmdline_fixed_string_t tx_first; 6836 uint32_t tx_num; 6837 }; 6838 6839 static void 6840 cmd_start_tx_first_n_parsed(void *parsed_result, 6841 __rte_unused struct cmdline *cl, 6842 __rte_unused void *data) 6843 { 6844 struct cmd_start_tx_first_n_result *res = parsed_result; 6845 6846 start_packet_forwarding(res->tx_num); 6847 } 6848 6849 static cmdline_parse_token_string_t cmd_start_tx_first_n_start = 6850 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result, 6851 start, "start"); 6852 static cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first = 6853 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result, 6854 tx_first, "tx_first"); 6855 static cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num = 6856 TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result, 6857 tx_num, RTE_UINT32); 6858 6859 static cmdline_parse_inst_t cmd_start_tx_first_n = { 6860 .f = cmd_start_tx_first_n_parsed, 6861 .data = NULL, 6862 .help_str = "start tx_first <num>: " 6863 "packet forwarding, after sending <num> bursts of packets", 6864 .tokens = { 6865 (void *)&cmd_start_tx_first_n_start, 6866 (void *)&cmd_start_tx_first_n_tx_first, 6867 (void *)&cmd_start_tx_first_n_tx_num, 6868 NULL, 6869 }, 6870 }; 6871 6872 /* *** SET LINK UP *** */ 6873 struct cmd_set_link_up_result { 6874 cmdline_fixed_string_t set; 6875 cmdline_fixed_string_t link_up; 6876 cmdline_fixed_string_t port; 6877 portid_t port_id; 6878 }; 6879 6880 static cmdline_parse_token_string_t cmd_set_link_up_set = 6881 TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set"); 6882 static cmdline_parse_token_string_t cmd_set_link_up_link_up = 6883 TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up, 6884 "link-up"); 6885 static cmdline_parse_token_string_t cmd_set_link_up_port = 6886 TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port"); 6887 static cmdline_parse_token_num_t cmd_set_link_up_port_id = 6888 TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, 6889 RTE_UINT16); 6890 6891 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result, 6892 __rte_unused struct cmdline *cl, 6893 __rte_unused void *data) 6894 { 6895 struct cmd_set_link_up_result *res = parsed_result; 6896 dev_set_link_up(res->port_id); 6897 } 6898 6899 static cmdline_parse_inst_t cmd_set_link_up = { 6900 .f = cmd_set_link_up_parsed, 6901 .data = NULL, 6902 .help_str = "set link-up port <port id>", 6903 .tokens = { 6904 (void *)&cmd_set_link_up_set, 6905 (void *)&cmd_set_link_up_link_up, 6906 (void *)&cmd_set_link_up_port, 6907 (void *)&cmd_set_link_up_port_id, 6908 NULL, 6909 }, 6910 }; 6911 6912 /* *** SET LINK DOWN *** */ 6913 struct cmd_set_link_down_result { 6914 cmdline_fixed_string_t set; 6915 cmdline_fixed_string_t link_down; 6916 cmdline_fixed_string_t port; 6917 portid_t port_id; 6918 }; 6919 6920 static cmdline_parse_token_string_t cmd_set_link_down_set = 6921 TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set"); 6922 static cmdline_parse_token_string_t cmd_set_link_down_link_down = 6923 TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down, 6924 "link-down"); 6925 static cmdline_parse_token_string_t cmd_set_link_down_port = 6926 TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port"); 6927 static cmdline_parse_token_num_t cmd_set_link_down_port_id = 6928 TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, 6929 RTE_UINT16); 6930 6931 static void cmd_set_link_down_parsed( 6932 __rte_unused void *parsed_result, 6933 __rte_unused struct cmdline *cl, 6934 __rte_unused void *data) 6935 { 6936 struct cmd_set_link_down_result *res = parsed_result; 6937 dev_set_link_down(res->port_id); 6938 } 6939 6940 static cmdline_parse_inst_t cmd_set_link_down = { 6941 .f = cmd_set_link_down_parsed, 6942 .data = NULL, 6943 .help_str = "set link-down port <port id>", 6944 .tokens = { 6945 (void *)&cmd_set_link_down_set, 6946 (void *)&cmd_set_link_down_link_down, 6947 (void *)&cmd_set_link_down_port, 6948 (void *)&cmd_set_link_down_port_id, 6949 NULL, 6950 }, 6951 }; 6952 6953 /* *** SHOW CFG *** */ 6954 struct cmd_showcfg_result { 6955 cmdline_fixed_string_t show; 6956 cmdline_fixed_string_t cfg; 6957 cmdline_fixed_string_t what; 6958 }; 6959 6960 static void cmd_showcfg_parsed(void *parsed_result, 6961 __rte_unused struct cmdline *cl, 6962 __rte_unused void *data) 6963 { 6964 struct cmd_showcfg_result *res = parsed_result; 6965 if (!strcmp(res->what, "rxtx")) 6966 rxtx_config_display(); 6967 else if (!strcmp(res->what, "cores")) 6968 fwd_lcores_config_display(); 6969 else if (!strcmp(res->what, "fwd")) 6970 pkt_fwd_config_display(&cur_fwd_config); 6971 else if (!strcmp(res->what, "rxoffs")) 6972 show_rx_pkt_offsets(); 6973 else if (!strcmp(res->what, "rxpkts")) 6974 show_rx_pkt_segments(); 6975 else if (!strcmp(res->what, "txpkts")) 6976 show_tx_pkt_segments(); 6977 else if (!strcmp(res->what, "txtimes")) 6978 show_tx_pkt_times(); 6979 } 6980 6981 static cmdline_parse_token_string_t cmd_showcfg_show = 6982 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show"); 6983 static cmdline_parse_token_string_t cmd_showcfg_port = 6984 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config"); 6985 static cmdline_parse_token_string_t cmd_showcfg_what = 6986 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what, 6987 "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes"); 6988 6989 static cmdline_parse_inst_t cmd_showcfg = { 6990 .f = cmd_showcfg_parsed, 6991 .data = NULL, 6992 .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes", 6993 .tokens = { 6994 (void *)&cmd_showcfg_show, 6995 (void *)&cmd_showcfg_port, 6996 (void *)&cmd_showcfg_what, 6997 NULL, 6998 }, 6999 }; 7000 7001 /* *** SHOW ALL PORT INFO *** */ 7002 struct cmd_showportall_result { 7003 cmdline_fixed_string_t show; 7004 cmdline_fixed_string_t port; 7005 cmdline_fixed_string_t what; 7006 cmdline_fixed_string_t all; 7007 }; 7008 7009 static void cmd_showportall_parsed(void *parsed_result, 7010 __rte_unused struct cmdline *cl, 7011 __rte_unused void *data) 7012 { 7013 portid_t i; 7014 7015 struct cmd_showportall_result *res = parsed_result; 7016 if (!strcmp(res->show, "clear")) { 7017 if (!strcmp(res->what, "stats")) 7018 RTE_ETH_FOREACH_DEV(i) 7019 nic_stats_clear(i); 7020 else if (!strcmp(res->what, "xstats")) 7021 RTE_ETH_FOREACH_DEV(i) 7022 nic_xstats_clear(i); 7023 } else if (!strcmp(res->what, "info")) 7024 RTE_ETH_FOREACH_DEV(i) 7025 port_infos_display(i); 7026 else if (!strcmp(res->what, "summary")) { 7027 port_summary_header_display(); 7028 RTE_ETH_FOREACH_DEV(i) 7029 port_summary_display(i); 7030 } 7031 else if (!strcmp(res->what, "stats")) 7032 RTE_ETH_FOREACH_DEV(i) 7033 nic_stats_display(i); 7034 else if (!strcmp(res->what, "xstats")) 7035 RTE_ETH_FOREACH_DEV(i) 7036 nic_xstats_display(i); 7037 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE) 7038 else if (!strcmp(res->what, "fdir")) 7039 RTE_ETH_FOREACH_DEV(i) 7040 fdir_get_infos(i); 7041 #endif 7042 else if (!strcmp(res->what, "dcb_tc")) 7043 RTE_ETH_FOREACH_DEV(i) 7044 port_dcb_info_display(i); 7045 } 7046 7047 static cmdline_parse_token_string_t cmd_showportall_show = 7048 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show, 7049 "show#clear"); 7050 static cmdline_parse_token_string_t cmd_showportall_port = 7051 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port"); 7052 static cmdline_parse_token_string_t cmd_showportall_what = 7053 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what, 7054 "info#summary#stats#xstats#fdir#dcb_tc"); 7055 static cmdline_parse_token_string_t cmd_showportall_all = 7056 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all"); 7057 static cmdline_parse_inst_t cmd_showportall = { 7058 .f = cmd_showportall_parsed, 7059 .data = NULL, 7060 .help_str = "show|clear port " 7061 "info|summary|stats|xstats|fdir|dcb_tc all", 7062 .tokens = { 7063 (void *)&cmd_showportall_show, 7064 (void *)&cmd_showportall_port, 7065 (void *)&cmd_showportall_what, 7066 (void *)&cmd_showportall_all, 7067 NULL, 7068 }, 7069 }; 7070 7071 /* *** SHOW PORT INFO *** */ 7072 struct cmd_showport_result { 7073 cmdline_fixed_string_t show; 7074 cmdline_fixed_string_t port; 7075 cmdline_fixed_string_t what; 7076 uint16_t portnum; 7077 }; 7078 7079 static void cmd_showport_parsed(void *parsed_result, 7080 __rte_unused struct cmdline *cl, 7081 __rte_unused void *data) 7082 { 7083 struct cmd_showport_result *res = parsed_result; 7084 if (!strcmp(res->show, "clear")) { 7085 if (!strcmp(res->what, "stats")) 7086 nic_stats_clear(res->portnum); 7087 else if (!strcmp(res->what, "xstats")) 7088 nic_xstats_clear(res->portnum); 7089 } else if (!strcmp(res->what, "info")) 7090 port_infos_display(res->portnum); 7091 else if (!strcmp(res->what, "summary")) { 7092 port_summary_header_display(); 7093 port_summary_display(res->portnum); 7094 } 7095 else if (!strcmp(res->what, "stats")) 7096 nic_stats_display(res->portnum); 7097 else if (!strcmp(res->what, "xstats")) 7098 nic_xstats_display(res->portnum); 7099 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE) 7100 else if (!strcmp(res->what, "fdir")) 7101 fdir_get_infos(res->portnum); 7102 #endif 7103 else if (!strcmp(res->what, "dcb_tc")) 7104 port_dcb_info_display(res->portnum); 7105 } 7106 7107 static cmdline_parse_token_string_t cmd_showport_show = 7108 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show, 7109 "show#clear"); 7110 static cmdline_parse_token_string_t cmd_showport_port = 7111 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port"); 7112 static cmdline_parse_token_string_t cmd_showport_what = 7113 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what, 7114 "info#summary#stats#xstats#fdir#dcb_tc"); 7115 static cmdline_parse_token_num_t cmd_showport_portnum = 7116 TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, RTE_UINT16); 7117 7118 static cmdline_parse_inst_t cmd_showport = { 7119 .f = cmd_showport_parsed, 7120 .data = NULL, 7121 .help_str = "show|clear port " 7122 "info|summary|stats|xstats|fdir|dcb_tc " 7123 "<port_id>", 7124 .tokens = { 7125 (void *)&cmd_showport_show, 7126 (void *)&cmd_showport_port, 7127 (void *)&cmd_showport_what, 7128 (void *)&cmd_showport_portnum, 7129 NULL, 7130 }, 7131 }; 7132 7133 /* *** show port representors information *** */ 7134 struct cmd_representor_info_result { 7135 cmdline_fixed_string_t cmd_show; 7136 cmdline_fixed_string_t cmd_port; 7137 cmdline_fixed_string_t cmd_info; 7138 cmdline_fixed_string_t cmd_keyword; 7139 portid_t cmd_pid; 7140 }; 7141 7142 static void 7143 cmd_representor_info_parsed(void *parsed_result, 7144 __rte_unused struct cmdline *cl, 7145 __rte_unused void *data) 7146 { 7147 struct cmd_representor_info_result *res = parsed_result; 7148 struct rte_eth_representor_info *info; 7149 struct rte_eth_representor_range *range; 7150 uint32_t range_diff; 7151 uint32_t i; 7152 int ret; 7153 int num; 7154 7155 if (!rte_eth_dev_is_valid_port(res->cmd_pid)) { 7156 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid); 7157 return; 7158 } 7159 7160 ret = rte_eth_representor_info_get(res->cmd_pid, NULL); 7161 if (ret < 0) { 7162 fprintf(stderr, 7163 "Failed to get the number of representor info ranges for port %hu: %s\n", 7164 res->cmd_pid, rte_strerror(-ret)); 7165 return; 7166 } 7167 num = ret; 7168 7169 info = calloc(1, sizeof(*info) + num * sizeof(info->ranges[0])); 7170 if (info == NULL) { 7171 fprintf(stderr, 7172 "Failed to allocate memory for representor info for port %hu\n", 7173 res->cmd_pid); 7174 return; 7175 } 7176 info->nb_ranges_alloc = num; 7177 7178 ret = rte_eth_representor_info_get(res->cmd_pid, info); 7179 if (ret < 0) { 7180 fprintf(stderr, 7181 "Failed to get the representor info for port %hu: %s\n", 7182 res->cmd_pid, rte_strerror(-ret)); 7183 free(info); 7184 return; 7185 } 7186 7187 printf("Port controller: %hu\n", info->controller); 7188 printf("Port PF: %hu\n", info->pf); 7189 7190 printf("Ranges: %u\n", info->nb_ranges); 7191 for (i = 0; i < info->nb_ranges; i++) { 7192 range = &info->ranges[i]; 7193 range_diff = range->id_end - range->id_base; 7194 7195 printf("%u. ", i + 1); 7196 printf("'%s' ", range->name); 7197 if (range_diff > 0) 7198 printf("[%u-%u]: ", range->id_base, range->id_end); 7199 else 7200 printf("[%u]: ", range->id_base); 7201 7202 printf("Controller %d, PF %d", range->controller, range->pf); 7203 7204 switch (range->type) { 7205 case RTE_ETH_REPRESENTOR_NONE: 7206 printf(", NONE\n"); 7207 break; 7208 case RTE_ETH_REPRESENTOR_VF: 7209 if (range_diff > 0) 7210 printf(", VF %d..%d\n", range->vf, 7211 range->vf + range_diff); 7212 else 7213 printf(", VF %d\n", range->vf); 7214 break; 7215 case RTE_ETH_REPRESENTOR_SF: 7216 printf(", SF %d\n", range->sf); 7217 break; 7218 case RTE_ETH_REPRESENTOR_PF: 7219 if (range_diff > 0) 7220 printf("..%d\n", range->pf + range_diff); 7221 else 7222 printf("\n"); 7223 break; 7224 default: 7225 printf(", UNKNOWN TYPE %d\n", range->type); 7226 break; 7227 } 7228 } 7229 7230 free(info); 7231 } 7232 7233 static cmdline_parse_token_string_t cmd_representor_info_show = 7234 TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result, 7235 cmd_show, "show"); 7236 static cmdline_parse_token_string_t cmd_representor_info_port = 7237 TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result, 7238 cmd_port, "port"); 7239 static cmdline_parse_token_string_t cmd_representor_info_info = 7240 TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result, 7241 cmd_info, "info"); 7242 static cmdline_parse_token_num_t cmd_representor_info_pid = 7243 TOKEN_NUM_INITIALIZER(struct cmd_representor_info_result, 7244 cmd_pid, RTE_UINT16); 7245 static cmdline_parse_token_string_t cmd_representor_info_keyword = 7246 TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result, 7247 cmd_keyword, "representor"); 7248 7249 static cmdline_parse_inst_t cmd_representor_info = { 7250 .f = cmd_representor_info_parsed, 7251 .data = NULL, 7252 .help_str = "show port info <port_id> representor", 7253 .tokens = { 7254 (void *)&cmd_representor_info_show, 7255 (void *)&cmd_representor_info_port, 7256 (void *)&cmd_representor_info_info, 7257 (void *)&cmd_representor_info_pid, 7258 (void *)&cmd_representor_info_keyword, 7259 NULL, 7260 }, 7261 }; 7262 7263 7264 /* *** SHOW DEVICE INFO *** */ 7265 struct cmd_showdevice_result { 7266 cmdline_fixed_string_t show; 7267 cmdline_fixed_string_t device; 7268 cmdline_fixed_string_t what; 7269 cmdline_fixed_string_t identifier; 7270 }; 7271 7272 static void cmd_showdevice_parsed(void *parsed_result, 7273 __rte_unused struct cmdline *cl, 7274 __rte_unused void *data) 7275 { 7276 struct cmd_showdevice_result *res = parsed_result; 7277 if (!strcmp(res->what, "info")) { 7278 if (!strcmp(res->identifier, "all")) 7279 device_infos_display(NULL); 7280 else 7281 device_infos_display(res->identifier); 7282 } 7283 } 7284 7285 static cmdline_parse_token_string_t cmd_showdevice_show = 7286 TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show, 7287 "show"); 7288 static cmdline_parse_token_string_t cmd_showdevice_device = 7289 TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device"); 7290 static cmdline_parse_token_string_t cmd_showdevice_what = 7291 TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what, 7292 "info"); 7293 static cmdline_parse_token_string_t cmd_showdevice_identifier = 7294 TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, 7295 identifier, NULL); 7296 7297 static cmdline_parse_inst_t cmd_showdevice = { 7298 .f = cmd_showdevice_parsed, 7299 .data = NULL, 7300 .help_str = "show device info <identifier>|all", 7301 .tokens = { 7302 (void *)&cmd_showdevice_show, 7303 (void *)&cmd_showdevice_device, 7304 (void *)&cmd_showdevice_what, 7305 (void *)&cmd_showdevice_identifier, 7306 NULL, 7307 }, 7308 }; 7309 7310 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */ 7311 struct cmd_showeeprom_result { 7312 cmdline_fixed_string_t show; 7313 cmdline_fixed_string_t port; 7314 uint16_t portnum; 7315 cmdline_fixed_string_t type; 7316 }; 7317 7318 static void cmd_showeeprom_parsed(void *parsed_result, 7319 __rte_unused struct cmdline *cl, 7320 __rte_unused void *data) 7321 { 7322 struct cmd_showeeprom_result *res = parsed_result; 7323 7324 if (!strcmp(res->type, "eeprom")) 7325 port_eeprom_display(res->portnum); 7326 else if (!strcmp(res->type, "module_eeprom")) 7327 port_module_eeprom_display(res->portnum); 7328 else 7329 fprintf(stderr, "Unknown argument\n"); 7330 } 7331 7332 static cmdline_parse_token_string_t cmd_showeeprom_show = 7333 TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show"); 7334 static cmdline_parse_token_string_t cmd_showeeprom_port = 7335 TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port"); 7336 static cmdline_parse_token_num_t cmd_showeeprom_portnum = 7337 TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum, 7338 RTE_UINT16); 7339 static cmdline_parse_token_string_t cmd_showeeprom_type = 7340 TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom"); 7341 7342 static cmdline_parse_inst_t cmd_showeeprom = { 7343 .f = cmd_showeeprom_parsed, 7344 .data = NULL, 7345 .help_str = "show port <port_id> module_eeprom|eeprom", 7346 .tokens = { 7347 (void *)&cmd_showeeprom_show, 7348 (void *)&cmd_showeeprom_port, 7349 (void *)&cmd_showeeprom_portnum, 7350 (void *)&cmd_showeeprom_type, 7351 NULL, 7352 }, 7353 }; 7354 7355 /* *** SHOW QUEUE INFO *** */ 7356 struct cmd_showqueue_result { 7357 cmdline_fixed_string_t show; 7358 cmdline_fixed_string_t type; 7359 cmdline_fixed_string_t what; 7360 uint16_t portnum; 7361 uint16_t queuenum; 7362 }; 7363 7364 static void 7365 cmd_showqueue_parsed(void *parsed_result, 7366 __rte_unused struct cmdline *cl, 7367 __rte_unused void *data) 7368 { 7369 struct cmd_showqueue_result *res = parsed_result; 7370 7371 if (!strcmp(res->type, "rxq")) 7372 rx_queue_infos_display(res->portnum, res->queuenum); 7373 else if (!strcmp(res->type, "txq")) 7374 tx_queue_infos_display(res->portnum, res->queuenum); 7375 } 7376 7377 static cmdline_parse_token_string_t cmd_showqueue_show = 7378 TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show"); 7379 static cmdline_parse_token_string_t cmd_showqueue_type = 7380 TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq"); 7381 static cmdline_parse_token_string_t cmd_showqueue_what = 7382 TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info"); 7383 static cmdline_parse_token_num_t cmd_showqueue_portnum = 7384 TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, 7385 RTE_UINT16); 7386 static cmdline_parse_token_num_t cmd_showqueue_queuenum = 7387 TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, 7388 RTE_UINT16); 7389 7390 static cmdline_parse_inst_t cmd_showqueue = { 7391 .f = cmd_showqueue_parsed, 7392 .data = NULL, 7393 .help_str = "show rxq|txq info <port_id> <queue_id>", 7394 .tokens = { 7395 (void *)&cmd_showqueue_show, 7396 (void *)&cmd_showqueue_type, 7397 (void *)&cmd_showqueue_what, 7398 (void *)&cmd_showqueue_portnum, 7399 (void *)&cmd_showqueue_queuenum, 7400 NULL, 7401 }, 7402 }; 7403 7404 /* show/clear fwd engine statistics */ 7405 struct fwd_result { 7406 cmdline_fixed_string_t action; 7407 cmdline_fixed_string_t fwd; 7408 cmdline_fixed_string_t stats; 7409 cmdline_fixed_string_t all; 7410 }; 7411 7412 static cmdline_parse_token_string_t cmd_fwd_action = 7413 TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear"); 7414 static cmdline_parse_token_string_t cmd_fwd_fwd = 7415 TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd"); 7416 static cmdline_parse_token_string_t cmd_fwd_stats = 7417 TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats"); 7418 static cmdline_parse_token_string_t cmd_fwd_all = 7419 TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all"); 7420 7421 static void 7422 cmd_showfwdall_parsed(void *parsed_result, 7423 __rte_unused struct cmdline *cl, 7424 __rte_unused void *data) 7425 { 7426 struct fwd_result *res = parsed_result; 7427 7428 if (!strcmp(res->action, "show")) 7429 fwd_stats_display(); 7430 else 7431 fwd_stats_reset(); 7432 } 7433 7434 static cmdline_parse_inst_t cmd_showfwdall = { 7435 .f = cmd_showfwdall_parsed, 7436 .data = NULL, 7437 .help_str = "show|clear fwd stats all", 7438 .tokens = { 7439 (void *)&cmd_fwd_action, 7440 (void *)&cmd_fwd_fwd, 7441 (void *)&cmd_fwd_stats, 7442 (void *)&cmd_fwd_all, 7443 NULL, 7444 }, 7445 }; 7446 7447 /* *** READ PORT REGISTER *** */ 7448 struct cmd_read_reg_result { 7449 cmdline_fixed_string_t read; 7450 cmdline_fixed_string_t reg; 7451 portid_t port_id; 7452 uint32_t reg_off; 7453 }; 7454 7455 static void 7456 cmd_read_reg_parsed(void *parsed_result, 7457 __rte_unused struct cmdline *cl, 7458 __rte_unused void *data) 7459 { 7460 struct cmd_read_reg_result *res = parsed_result; 7461 port_reg_display(res->port_id, res->reg_off); 7462 } 7463 7464 static cmdline_parse_token_string_t cmd_read_reg_read = 7465 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read"); 7466 static cmdline_parse_token_string_t cmd_read_reg_reg = 7467 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg"); 7468 static cmdline_parse_token_num_t cmd_read_reg_port_id = 7469 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, RTE_UINT16); 7470 static cmdline_parse_token_num_t cmd_read_reg_reg_off = 7471 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, RTE_UINT32); 7472 7473 static cmdline_parse_inst_t cmd_read_reg = { 7474 .f = cmd_read_reg_parsed, 7475 .data = NULL, 7476 .help_str = "read reg <port_id> <reg_off>", 7477 .tokens = { 7478 (void *)&cmd_read_reg_read, 7479 (void *)&cmd_read_reg_reg, 7480 (void *)&cmd_read_reg_port_id, 7481 (void *)&cmd_read_reg_reg_off, 7482 NULL, 7483 }, 7484 }; 7485 7486 /* *** READ PORT REGISTER BIT FIELD *** */ 7487 struct cmd_read_reg_bit_field_result { 7488 cmdline_fixed_string_t read; 7489 cmdline_fixed_string_t regfield; 7490 portid_t port_id; 7491 uint32_t reg_off; 7492 uint8_t bit1_pos; 7493 uint8_t bit2_pos; 7494 }; 7495 7496 static void 7497 cmd_read_reg_bit_field_parsed(void *parsed_result, 7498 __rte_unused struct cmdline *cl, 7499 __rte_unused void *data) 7500 { 7501 struct cmd_read_reg_bit_field_result *res = parsed_result; 7502 port_reg_bit_field_display(res->port_id, res->reg_off, 7503 res->bit1_pos, res->bit2_pos); 7504 } 7505 7506 static cmdline_parse_token_string_t cmd_read_reg_bit_field_read = 7507 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read, 7508 "read"); 7509 static cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield = 7510 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, 7511 regfield, "regfield"); 7512 static cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id = 7513 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id, 7514 RTE_UINT16); 7515 static cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off = 7516 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off, 7517 RTE_UINT32); 7518 static cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos = 7519 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos, 7520 RTE_UINT8); 7521 static cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos = 7522 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos, 7523 RTE_UINT8); 7524 7525 static cmdline_parse_inst_t cmd_read_reg_bit_field = { 7526 .f = cmd_read_reg_bit_field_parsed, 7527 .data = NULL, 7528 .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: " 7529 "Read register bit field between bit_x and bit_y included", 7530 .tokens = { 7531 (void *)&cmd_read_reg_bit_field_read, 7532 (void *)&cmd_read_reg_bit_field_regfield, 7533 (void *)&cmd_read_reg_bit_field_port_id, 7534 (void *)&cmd_read_reg_bit_field_reg_off, 7535 (void *)&cmd_read_reg_bit_field_bit1_pos, 7536 (void *)&cmd_read_reg_bit_field_bit2_pos, 7537 NULL, 7538 }, 7539 }; 7540 7541 /* *** READ PORT REGISTER BIT *** */ 7542 struct cmd_read_reg_bit_result { 7543 cmdline_fixed_string_t read; 7544 cmdline_fixed_string_t regbit; 7545 portid_t port_id; 7546 uint32_t reg_off; 7547 uint8_t bit_pos; 7548 }; 7549 7550 static void 7551 cmd_read_reg_bit_parsed(void *parsed_result, 7552 __rte_unused struct cmdline *cl, 7553 __rte_unused void *data) 7554 { 7555 struct cmd_read_reg_bit_result *res = parsed_result; 7556 port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos); 7557 } 7558 7559 static cmdline_parse_token_string_t cmd_read_reg_bit_read = 7560 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read"); 7561 static cmdline_parse_token_string_t cmd_read_reg_bit_regbit = 7562 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, 7563 regbit, "regbit"); 7564 static cmdline_parse_token_num_t cmd_read_reg_bit_port_id = 7565 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, 7566 RTE_UINT16); 7567 static cmdline_parse_token_num_t cmd_read_reg_bit_reg_off = 7568 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, 7569 RTE_UINT32); 7570 static cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos = 7571 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, 7572 RTE_UINT8); 7573 7574 static cmdline_parse_inst_t cmd_read_reg_bit = { 7575 .f = cmd_read_reg_bit_parsed, 7576 .data = NULL, 7577 .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31", 7578 .tokens = { 7579 (void *)&cmd_read_reg_bit_read, 7580 (void *)&cmd_read_reg_bit_regbit, 7581 (void *)&cmd_read_reg_bit_port_id, 7582 (void *)&cmd_read_reg_bit_reg_off, 7583 (void *)&cmd_read_reg_bit_bit_pos, 7584 NULL, 7585 }, 7586 }; 7587 7588 /* *** WRITE PORT REGISTER *** */ 7589 struct cmd_write_reg_result { 7590 cmdline_fixed_string_t write; 7591 cmdline_fixed_string_t reg; 7592 portid_t port_id; 7593 uint32_t reg_off; 7594 uint32_t value; 7595 }; 7596 7597 static void 7598 cmd_write_reg_parsed(void *parsed_result, 7599 __rte_unused struct cmdline *cl, 7600 __rte_unused void *data) 7601 { 7602 struct cmd_write_reg_result *res = parsed_result; 7603 port_reg_set(res->port_id, res->reg_off, res->value); 7604 } 7605 7606 static cmdline_parse_token_string_t cmd_write_reg_write = 7607 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write"); 7608 static cmdline_parse_token_string_t cmd_write_reg_reg = 7609 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg"); 7610 static cmdline_parse_token_num_t cmd_write_reg_port_id = 7611 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, RTE_UINT16); 7612 static cmdline_parse_token_num_t cmd_write_reg_reg_off = 7613 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, RTE_UINT32); 7614 static cmdline_parse_token_num_t cmd_write_reg_value = 7615 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, RTE_UINT32); 7616 7617 static cmdline_parse_inst_t cmd_write_reg = { 7618 .f = cmd_write_reg_parsed, 7619 .data = NULL, 7620 .help_str = "write reg <port_id> <reg_off> <reg_value>", 7621 .tokens = { 7622 (void *)&cmd_write_reg_write, 7623 (void *)&cmd_write_reg_reg, 7624 (void *)&cmd_write_reg_port_id, 7625 (void *)&cmd_write_reg_reg_off, 7626 (void *)&cmd_write_reg_value, 7627 NULL, 7628 }, 7629 }; 7630 7631 /* *** WRITE PORT REGISTER BIT FIELD *** */ 7632 struct cmd_write_reg_bit_field_result { 7633 cmdline_fixed_string_t write; 7634 cmdline_fixed_string_t regfield; 7635 portid_t port_id; 7636 uint32_t reg_off; 7637 uint8_t bit1_pos; 7638 uint8_t bit2_pos; 7639 uint32_t value; 7640 }; 7641 7642 static void 7643 cmd_write_reg_bit_field_parsed(void *parsed_result, 7644 __rte_unused struct cmdline *cl, 7645 __rte_unused void *data) 7646 { 7647 struct cmd_write_reg_bit_field_result *res = parsed_result; 7648 port_reg_bit_field_set(res->port_id, res->reg_off, 7649 res->bit1_pos, res->bit2_pos, res->value); 7650 } 7651 7652 static cmdline_parse_token_string_t cmd_write_reg_bit_field_write = 7653 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write, 7654 "write"); 7655 static cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield = 7656 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, 7657 regfield, "regfield"); 7658 static cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id = 7659 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id, 7660 RTE_UINT16); 7661 static cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off = 7662 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off, 7663 RTE_UINT32); 7664 static cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos = 7665 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos, 7666 RTE_UINT8); 7667 static cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos = 7668 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos, 7669 RTE_UINT8); 7670 static cmdline_parse_token_num_t cmd_write_reg_bit_field_value = 7671 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value, 7672 RTE_UINT32); 7673 7674 static cmdline_parse_inst_t cmd_write_reg_bit_field = { 7675 .f = cmd_write_reg_bit_field_parsed, 7676 .data = NULL, 7677 .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> " 7678 "<reg_value>: " 7679 "Set register bit field between bit_x and bit_y included", 7680 .tokens = { 7681 (void *)&cmd_write_reg_bit_field_write, 7682 (void *)&cmd_write_reg_bit_field_regfield, 7683 (void *)&cmd_write_reg_bit_field_port_id, 7684 (void *)&cmd_write_reg_bit_field_reg_off, 7685 (void *)&cmd_write_reg_bit_field_bit1_pos, 7686 (void *)&cmd_write_reg_bit_field_bit2_pos, 7687 (void *)&cmd_write_reg_bit_field_value, 7688 NULL, 7689 }, 7690 }; 7691 7692 /* *** WRITE PORT REGISTER BIT *** */ 7693 struct cmd_write_reg_bit_result { 7694 cmdline_fixed_string_t write; 7695 cmdline_fixed_string_t regbit; 7696 portid_t port_id; 7697 uint32_t reg_off; 7698 uint8_t bit_pos; 7699 uint8_t value; 7700 }; 7701 7702 static void 7703 cmd_write_reg_bit_parsed(void *parsed_result, 7704 __rte_unused struct cmdline *cl, 7705 __rte_unused void *data) 7706 { 7707 struct cmd_write_reg_bit_result *res = parsed_result; 7708 port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value); 7709 } 7710 7711 static cmdline_parse_token_string_t cmd_write_reg_bit_write = 7712 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write, 7713 "write"); 7714 static cmdline_parse_token_string_t cmd_write_reg_bit_regbit = 7715 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, 7716 regbit, "regbit"); 7717 static cmdline_parse_token_num_t cmd_write_reg_bit_port_id = 7718 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, 7719 RTE_UINT16); 7720 static cmdline_parse_token_num_t cmd_write_reg_bit_reg_off = 7721 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, 7722 RTE_UINT32); 7723 static cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos = 7724 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, 7725 RTE_UINT8); 7726 static cmdline_parse_token_num_t cmd_write_reg_bit_value = 7727 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, 7728 RTE_UINT8); 7729 7730 static cmdline_parse_inst_t cmd_write_reg_bit = { 7731 .f = cmd_write_reg_bit_parsed, 7732 .data = NULL, 7733 .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: " 7734 "0 <= bit_x <= 31", 7735 .tokens = { 7736 (void *)&cmd_write_reg_bit_write, 7737 (void *)&cmd_write_reg_bit_regbit, 7738 (void *)&cmd_write_reg_bit_port_id, 7739 (void *)&cmd_write_reg_bit_reg_off, 7740 (void *)&cmd_write_reg_bit_bit_pos, 7741 (void *)&cmd_write_reg_bit_value, 7742 NULL, 7743 }, 7744 }; 7745 7746 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */ 7747 struct cmd_read_rxd_txd_result { 7748 cmdline_fixed_string_t read; 7749 cmdline_fixed_string_t rxd_txd; 7750 portid_t port_id; 7751 uint16_t queue_id; 7752 uint16_t desc_id; 7753 }; 7754 7755 static void 7756 cmd_read_rxd_txd_parsed(void *parsed_result, 7757 __rte_unused struct cmdline *cl, 7758 __rte_unused void *data) 7759 { 7760 struct cmd_read_rxd_txd_result *res = parsed_result; 7761 7762 if (!strcmp(res->rxd_txd, "rxd")) 7763 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id); 7764 else if (!strcmp(res->rxd_txd, "txd")) 7765 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id); 7766 } 7767 7768 static cmdline_parse_token_string_t cmd_read_rxd_txd_read = 7769 TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read"); 7770 static cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd = 7771 TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd, 7772 "rxd#txd"); 7773 static cmdline_parse_token_num_t cmd_read_rxd_txd_port_id = 7774 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, 7775 RTE_UINT16); 7776 static cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id = 7777 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, 7778 RTE_UINT16); 7779 static cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id = 7780 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, 7781 RTE_UINT16); 7782 7783 static cmdline_parse_inst_t cmd_read_rxd_txd = { 7784 .f = cmd_read_rxd_txd_parsed, 7785 .data = NULL, 7786 .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>", 7787 .tokens = { 7788 (void *)&cmd_read_rxd_txd_read, 7789 (void *)&cmd_read_rxd_txd_rxd_txd, 7790 (void *)&cmd_read_rxd_txd_port_id, 7791 (void *)&cmd_read_rxd_txd_queue_id, 7792 (void *)&cmd_read_rxd_txd_desc_id, 7793 NULL, 7794 }, 7795 }; 7796 7797 /* *** QUIT *** */ 7798 struct cmd_quit_result { 7799 cmdline_fixed_string_t quit; 7800 }; 7801 7802 static void cmd_quit_parsed(__rte_unused void *parsed_result, 7803 struct cmdline *cl, 7804 __rte_unused void *data) 7805 { 7806 cmdline_quit(cl); 7807 cl_quit = 1; 7808 } 7809 7810 static cmdline_parse_token_string_t cmd_quit_quit = 7811 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit"); 7812 7813 static cmdline_parse_inst_t cmd_quit = { 7814 .f = cmd_quit_parsed, 7815 .data = NULL, 7816 .help_str = "quit: Exit application", 7817 .tokens = { 7818 (void *)&cmd_quit_quit, 7819 NULL, 7820 }, 7821 }; 7822 7823 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */ 7824 struct cmd_mac_addr_result { 7825 cmdline_fixed_string_t mac_addr_cmd; 7826 cmdline_fixed_string_t what; 7827 uint16_t port_num; 7828 struct rte_ether_addr address; 7829 }; 7830 7831 static void cmd_mac_addr_parsed(void *parsed_result, 7832 __rte_unused struct cmdline *cl, 7833 __rte_unused void *data) 7834 { 7835 struct cmd_mac_addr_result *res = parsed_result; 7836 int ret; 7837 7838 if (strcmp(res->what, "add") == 0) 7839 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0); 7840 else if (strcmp(res->what, "set") == 0) 7841 ret = rte_eth_dev_default_mac_addr_set(res->port_num, 7842 &res->address); 7843 else 7844 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address); 7845 7846 /* check the return value and print it if is < 0 */ 7847 if(ret < 0) 7848 fprintf(stderr, "mac_addr_cmd error: (%s)\n", strerror(-ret)); 7849 7850 } 7851 7852 static cmdline_parse_token_string_t cmd_mac_addr_cmd = 7853 TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd, 7854 "mac_addr"); 7855 static cmdline_parse_token_string_t cmd_mac_addr_what = 7856 TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what, 7857 "add#remove#set"); 7858 static cmdline_parse_token_num_t cmd_mac_addr_portnum = 7859 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, 7860 RTE_UINT16); 7861 static cmdline_parse_token_etheraddr_t cmd_mac_addr_addr = 7862 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address); 7863 7864 static cmdline_parse_inst_t cmd_mac_addr = { 7865 .f = cmd_mac_addr_parsed, 7866 .data = (void *)0, 7867 .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: " 7868 "Add/Remove/Set MAC address on port_id", 7869 .tokens = { 7870 (void *)&cmd_mac_addr_cmd, 7871 (void *)&cmd_mac_addr_what, 7872 (void *)&cmd_mac_addr_portnum, 7873 (void *)&cmd_mac_addr_addr, 7874 NULL, 7875 }, 7876 }; 7877 7878 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */ 7879 struct cmd_eth_peer_result { 7880 cmdline_fixed_string_t set; 7881 cmdline_fixed_string_t eth_peer; 7882 portid_t port_id; 7883 cmdline_fixed_string_t peer_addr; 7884 }; 7885 7886 static void cmd_set_eth_peer_parsed(void *parsed_result, 7887 __rte_unused struct cmdline *cl, 7888 __rte_unused void *data) 7889 { 7890 struct cmd_eth_peer_result *res = parsed_result; 7891 7892 if (test_done == 0) { 7893 fprintf(stderr, "Please stop forwarding first\n"); 7894 return; 7895 } 7896 if (!strcmp(res->eth_peer, "eth-peer")) { 7897 set_fwd_eth_peer(res->port_id, res->peer_addr); 7898 fwd_config_setup(); 7899 } 7900 } 7901 static cmdline_parse_token_string_t cmd_eth_peer_set = 7902 TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set"); 7903 static cmdline_parse_token_string_t cmd_eth_peer = 7904 TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer"); 7905 static cmdline_parse_token_num_t cmd_eth_peer_port_id = 7906 TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, 7907 RTE_UINT16); 7908 static cmdline_parse_token_string_t cmd_eth_peer_addr = 7909 TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL); 7910 7911 static cmdline_parse_inst_t cmd_set_fwd_eth_peer = { 7912 .f = cmd_set_eth_peer_parsed, 7913 .data = NULL, 7914 .help_str = "set eth-peer <port_id> <peer_mac>", 7915 .tokens = { 7916 (void *)&cmd_eth_peer_set, 7917 (void *)&cmd_eth_peer, 7918 (void *)&cmd_eth_peer_port_id, 7919 (void *)&cmd_eth_peer_addr, 7920 NULL, 7921 }, 7922 }; 7923 7924 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */ 7925 struct cmd_set_qmap_result { 7926 cmdline_fixed_string_t set; 7927 cmdline_fixed_string_t qmap; 7928 cmdline_fixed_string_t what; 7929 portid_t port_id; 7930 uint16_t queue_id; 7931 uint8_t map_value; 7932 }; 7933 7934 static void 7935 cmd_set_qmap_parsed(void *parsed_result, 7936 __rte_unused struct cmdline *cl, 7937 __rte_unused void *data) 7938 { 7939 struct cmd_set_qmap_result *res = parsed_result; 7940 int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1; 7941 7942 set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value); 7943 } 7944 7945 static cmdline_parse_token_string_t cmd_setqmap_set = 7946 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result, 7947 set, "set"); 7948 static cmdline_parse_token_string_t cmd_setqmap_qmap = 7949 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result, 7950 qmap, "stat_qmap"); 7951 static cmdline_parse_token_string_t cmd_setqmap_what = 7952 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result, 7953 what, "tx#rx"); 7954 static cmdline_parse_token_num_t cmd_setqmap_portid = 7955 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, 7956 port_id, RTE_UINT16); 7957 static cmdline_parse_token_num_t cmd_setqmap_queueid = 7958 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, 7959 queue_id, RTE_UINT16); 7960 static cmdline_parse_token_num_t cmd_setqmap_mapvalue = 7961 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, 7962 map_value, RTE_UINT8); 7963 7964 static cmdline_parse_inst_t cmd_set_qmap = { 7965 .f = cmd_set_qmap_parsed, 7966 .data = NULL, 7967 .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: " 7968 "Set statistics mapping value on tx|rx queue_id of port_id", 7969 .tokens = { 7970 (void *)&cmd_setqmap_set, 7971 (void *)&cmd_setqmap_qmap, 7972 (void *)&cmd_setqmap_what, 7973 (void *)&cmd_setqmap_portid, 7974 (void *)&cmd_setqmap_queueid, 7975 (void *)&cmd_setqmap_mapvalue, 7976 NULL, 7977 }, 7978 }; 7979 7980 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS DISPLAY *** */ 7981 struct cmd_set_xstats_hide_zero_result { 7982 cmdline_fixed_string_t keyword; 7983 cmdline_fixed_string_t name; 7984 cmdline_fixed_string_t on_off; 7985 }; 7986 7987 static void 7988 cmd_set_xstats_hide_zero_parsed(void *parsed_result, 7989 __rte_unused struct cmdline *cl, 7990 __rte_unused void *data) 7991 { 7992 struct cmd_set_xstats_hide_zero_result *res; 7993 uint16_t on_off = 0; 7994 7995 res = parsed_result; 7996 on_off = !strcmp(res->on_off, "on") ? 1 : 0; 7997 set_xstats_hide_zero(on_off); 7998 } 7999 8000 static cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword = 8001 TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result, 8002 keyword, "set"); 8003 static cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name = 8004 TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result, 8005 name, "xstats-hide-zero"); 8006 static cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off = 8007 TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result, 8008 on_off, "on#off"); 8009 8010 static cmdline_parse_inst_t cmd_set_xstats_hide_zero = { 8011 .f = cmd_set_xstats_hide_zero_parsed, 8012 .data = NULL, 8013 .help_str = "set xstats-hide-zero on|off", 8014 .tokens = { 8015 (void *)&cmd_set_xstats_hide_zero_keyword, 8016 (void *)&cmd_set_xstats_hide_zero_name, 8017 (void *)&cmd_set_xstats_hide_zero_on_off, 8018 NULL, 8019 }, 8020 }; 8021 8022 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */ 8023 struct cmd_set_record_core_cycles_result { 8024 cmdline_fixed_string_t keyword; 8025 cmdline_fixed_string_t name; 8026 cmdline_fixed_string_t on_off; 8027 }; 8028 8029 static void 8030 cmd_set_record_core_cycles_parsed(void *parsed_result, 8031 __rte_unused struct cmdline *cl, 8032 __rte_unused void *data) 8033 { 8034 struct cmd_set_record_core_cycles_result *res; 8035 uint16_t on_off = 0; 8036 8037 res = parsed_result; 8038 on_off = !strcmp(res->on_off, "on") ? 1 : 0; 8039 set_record_core_cycles(on_off); 8040 } 8041 8042 static cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword = 8043 TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result, 8044 keyword, "set"); 8045 static cmdline_parse_token_string_t cmd_set_record_core_cycles_name = 8046 TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result, 8047 name, "record-core-cycles"); 8048 static cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off = 8049 TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result, 8050 on_off, "on#off"); 8051 8052 static cmdline_parse_inst_t cmd_set_record_core_cycles = { 8053 .f = cmd_set_record_core_cycles_parsed, 8054 .data = NULL, 8055 .help_str = "set record-core-cycles on|off", 8056 .tokens = { 8057 (void *)&cmd_set_record_core_cycles_keyword, 8058 (void *)&cmd_set_record_core_cycles_name, 8059 (void *)&cmd_set_record_core_cycles_on_off, 8060 NULL, 8061 }, 8062 }; 8063 8064 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */ 8065 struct cmd_set_record_burst_stats_result { 8066 cmdline_fixed_string_t keyword; 8067 cmdline_fixed_string_t name; 8068 cmdline_fixed_string_t on_off; 8069 }; 8070 8071 static void 8072 cmd_set_record_burst_stats_parsed(void *parsed_result, 8073 __rte_unused struct cmdline *cl, 8074 __rte_unused void *data) 8075 { 8076 struct cmd_set_record_burst_stats_result *res; 8077 uint16_t on_off = 0; 8078 8079 res = parsed_result; 8080 on_off = !strcmp(res->on_off, "on") ? 1 : 0; 8081 set_record_burst_stats(on_off); 8082 } 8083 8084 static cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword = 8085 TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result, 8086 keyword, "set"); 8087 static cmdline_parse_token_string_t cmd_set_record_burst_stats_name = 8088 TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result, 8089 name, "record-burst-stats"); 8090 static cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off = 8091 TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result, 8092 on_off, "on#off"); 8093 8094 static cmdline_parse_inst_t cmd_set_record_burst_stats = { 8095 .f = cmd_set_record_burst_stats_parsed, 8096 .data = NULL, 8097 .help_str = "set record-burst-stats on|off", 8098 .tokens = { 8099 (void *)&cmd_set_record_burst_stats_keyword, 8100 (void *)&cmd_set_record_burst_stats_name, 8101 (void *)&cmd_set_record_burst_stats_on_off, 8102 NULL, 8103 }, 8104 }; 8105 8106 /* *** CONFIGURE UNICAST HASH TABLE *** */ 8107 struct cmd_set_uc_hash_table { 8108 cmdline_fixed_string_t set; 8109 cmdline_fixed_string_t port; 8110 portid_t port_id; 8111 cmdline_fixed_string_t what; 8112 struct rte_ether_addr address; 8113 cmdline_fixed_string_t mode; 8114 }; 8115 8116 static void 8117 cmd_set_uc_hash_parsed(void *parsed_result, 8118 __rte_unused struct cmdline *cl, 8119 __rte_unused void *data) 8120 { 8121 int ret=0; 8122 struct cmd_set_uc_hash_table *res = parsed_result; 8123 8124 int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 8125 8126 if (strcmp(res->what, "uta") == 0) 8127 ret = rte_eth_dev_uc_hash_table_set(res->port_id, 8128 &res->address,(uint8_t)is_on); 8129 if (ret < 0) 8130 fprintf(stderr, 8131 "bad unicast hash table parameter, return code = %d\n", 8132 ret); 8133 8134 } 8135 8136 static cmdline_parse_token_string_t cmd_set_uc_hash_set = 8137 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 8138 set, "set"); 8139 static cmdline_parse_token_string_t cmd_set_uc_hash_port = 8140 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 8141 port, "port"); 8142 static cmdline_parse_token_num_t cmd_set_uc_hash_portid = 8143 TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table, 8144 port_id, RTE_UINT16); 8145 static cmdline_parse_token_string_t cmd_set_uc_hash_what = 8146 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 8147 what, "uta"); 8148 static cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac = 8149 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table, 8150 address); 8151 static cmdline_parse_token_string_t cmd_set_uc_hash_mode = 8152 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 8153 mode, "on#off"); 8154 8155 static cmdline_parse_inst_t cmd_set_uc_hash_filter = { 8156 .f = cmd_set_uc_hash_parsed, 8157 .data = NULL, 8158 .help_str = "set port <port_id> uta <mac_addr> on|off)", 8159 .tokens = { 8160 (void *)&cmd_set_uc_hash_set, 8161 (void *)&cmd_set_uc_hash_port, 8162 (void *)&cmd_set_uc_hash_portid, 8163 (void *)&cmd_set_uc_hash_what, 8164 (void *)&cmd_set_uc_hash_mac, 8165 (void *)&cmd_set_uc_hash_mode, 8166 NULL, 8167 }, 8168 }; 8169 8170 struct cmd_set_uc_all_hash_table { 8171 cmdline_fixed_string_t set; 8172 cmdline_fixed_string_t port; 8173 portid_t port_id; 8174 cmdline_fixed_string_t what; 8175 cmdline_fixed_string_t value; 8176 cmdline_fixed_string_t mode; 8177 }; 8178 8179 static void 8180 cmd_set_uc_all_hash_parsed(void *parsed_result, 8181 __rte_unused struct cmdline *cl, 8182 __rte_unused void *data) 8183 { 8184 int ret=0; 8185 struct cmd_set_uc_all_hash_table *res = parsed_result; 8186 8187 int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 8188 8189 if ((strcmp(res->what, "uta") == 0) && 8190 (strcmp(res->value, "all") == 0)) 8191 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on); 8192 if (ret < 0) 8193 fprintf(stderr, 8194 "bad unicast hash table parameter, return code = %d\n", 8195 ret); 8196 } 8197 8198 static cmdline_parse_token_string_t cmd_set_uc_all_hash_set = 8199 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 8200 set, "set"); 8201 static cmdline_parse_token_string_t cmd_set_uc_all_hash_port = 8202 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 8203 port, "port"); 8204 static cmdline_parse_token_num_t cmd_set_uc_all_hash_portid = 8205 TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table, 8206 port_id, RTE_UINT16); 8207 static cmdline_parse_token_string_t cmd_set_uc_all_hash_what = 8208 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 8209 what, "uta"); 8210 static cmdline_parse_token_string_t cmd_set_uc_all_hash_value = 8211 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 8212 value,"all"); 8213 static cmdline_parse_token_string_t cmd_set_uc_all_hash_mode = 8214 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 8215 mode, "on#off"); 8216 8217 static cmdline_parse_inst_t cmd_set_uc_all_hash_filter = { 8218 .f = cmd_set_uc_all_hash_parsed, 8219 .data = NULL, 8220 .help_str = "set port <port_id> uta all on|off", 8221 .tokens = { 8222 (void *)&cmd_set_uc_all_hash_set, 8223 (void *)&cmd_set_uc_all_hash_port, 8224 (void *)&cmd_set_uc_all_hash_portid, 8225 (void *)&cmd_set_uc_all_hash_what, 8226 (void *)&cmd_set_uc_all_hash_value, 8227 (void *)&cmd_set_uc_all_hash_mode, 8228 NULL, 8229 }, 8230 }; 8231 8232 /* *** CONFIGURE VF TRAFFIC CONTROL *** */ 8233 struct cmd_set_vf_traffic { 8234 cmdline_fixed_string_t set; 8235 cmdline_fixed_string_t port; 8236 portid_t port_id; 8237 cmdline_fixed_string_t vf; 8238 uint8_t vf_id; 8239 cmdline_fixed_string_t what; 8240 cmdline_fixed_string_t mode; 8241 }; 8242 8243 static void 8244 cmd_set_vf_traffic_parsed(void *parsed_result, 8245 __rte_unused struct cmdline *cl, 8246 __rte_unused void *data) 8247 { 8248 struct cmd_set_vf_traffic *res = parsed_result; 8249 int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0; 8250 int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 8251 8252 set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on); 8253 } 8254 8255 static cmdline_parse_token_string_t cmd_setvf_traffic_set = 8256 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 8257 set, "set"); 8258 static cmdline_parse_token_string_t cmd_setvf_traffic_port = 8259 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 8260 port, "port"); 8261 static cmdline_parse_token_num_t cmd_setvf_traffic_portid = 8262 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic, 8263 port_id, RTE_UINT16); 8264 static cmdline_parse_token_string_t cmd_setvf_traffic_vf = 8265 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 8266 vf, "vf"); 8267 static cmdline_parse_token_num_t cmd_setvf_traffic_vfid = 8268 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic, 8269 vf_id, RTE_UINT8); 8270 static cmdline_parse_token_string_t cmd_setvf_traffic_what = 8271 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 8272 what, "tx#rx"); 8273 static cmdline_parse_token_string_t cmd_setvf_traffic_mode = 8274 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 8275 mode, "on#off"); 8276 8277 static cmdline_parse_inst_t cmd_set_vf_traffic = { 8278 .f = cmd_set_vf_traffic_parsed, 8279 .data = NULL, 8280 .help_str = "set port <port_id> vf <vf_id> rx|tx on|off", 8281 .tokens = { 8282 (void *)&cmd_setvf_traffic_set, 8283 (void *)&cmd_setvf_traffic_port, 8284 (void *)&cmd_setvf_traffic_portid, 8285 (void *)&cmd_setvf_traffic_vf, 8286 (void *)&cmd_setvf_traffic_vfid, 8287 (void *)&cmd_setvf_traffic_what, 8288 (void *)&cmd_setvf_traffic_mode, 8289 NULL, 8290 }, 8291 }; 8292 8293 /* *** CONFIGURE VF RECEIVE MODE *** */ 8294 struct cmd_set_vf_rxmode { 8295 cmdline_fixed_string_t set; 8296 cmdline_fixed_string_t port; 8297 portid_t port_id; 8298 cmdline_fixed_string_t vf; 8299 uint8_t vf_id; 8300 cmdline_fixed_string_t what; 8301 cmdline_fixed_string_t mode; 8302 cmdline_fixed_string_t on; 8303 }; 8304 8305 static void 8306 cmd_set_vf_rxmode_parsed(void *parsed_result, 8307 __rte_unused struct cmdline *cl, 8308 __rte_unused void *data) 8309 { 8310 int ret = -ENOTSUP; 8311 uint16_t vf_rxmode = 0; 8312 struct cmd_set_vf_rxmode *res = parsed_result; 8313 8314 int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0; 8315 if (!strcmp(res->what,"rxmode")) { 8316 if (!strcmp(res->mode, "AUPE")) 8317 vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_UNTAG; 8318 else if (!strcmp(res->mode, "ROPE")) 8319 vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_HASH_UC; 8320 else if (!strcmp(res->mode, "BAM")) 8321 vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_BROADCAST; 8322 else if (!strncmp(res->mode, "MPE",3)) 8323 vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_MULTICAST; 8324 } 8325 8326 RTE_SET_USED(is_on); 8327 RTE_SET_USED(vf_rxmode); 8328 8329 #ifdef RTE_NET_IXGBE 8330 if (ret == -ENOTSUP) 8331 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id, 8332 vf_rxmode, (uint8_t)is_on); 8333 #endif 8334 #ifdef RTE_NET_BNXT 8335 if (ret == -ENOTSUP) 8336 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id, 8337 vf_rxmode, (uint8_t)is_on); 8338 #endif 8339 if (ret < 0) 8340 fprintf(stderr, 8341 "bad VF receive mode parameter, return code = %d\n", 8342 ret); 8343 } 8344 8345 static cmdline_parse_token_string_t cmd_set_vf_rxmode_set = 8346 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 8347 set, "set"); 8348 static cmdline_parse_token_string_t cmd_set_vf_rxmode_port = 8349 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 8350 port, "port"); 8351 static cmdline_parse_token_num_t cmd_set_vf_rxmode_portid = 8352 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode, 8353 port_id, RTE_UINT16); 8354 static cmdline_parse_token_string_t cmd_set_vf_rxmode_vf = 8355 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 8356 vf, "vf"); 8357 static cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid = 8358 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode, 8359 vf_id, RTE_UINT8); 8360 static cmdline_parse_token_string_t cmd_set_vf_rxmode_what = 8361 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 8362 what, "rxmode"); 8363 static cmdline_parse_token_string_t cmd_set_vf_rxmode_mode = 8364 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 8365 mode, "AUPE#ROPE#BAM#MPE"); 8366 static cmdline_parse_token_string_t cmd_set_vf_rxmode_on = 8367 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 8368 on, "on#off"); 8369 8370 static cmdline_parse_inst_t cmd_set_vf_rxmode = { 8371 .f = cmd_set_vf_rxmode_parsed, 8372 .data = NULL, 8373 .help_str = "set port <port_id> vf <vf_id> rxmode " 8374 "AUPE|ROPE|BAM|MPE on|off", 8375 .tokens = { 8376 (void *)&cmd_set_vf_rxmode_set, 8377 (void *)&cmd_set_vf_rxmode_port, 8378 (void *)&cmd_set_vf_rxmode_portid, 8379 (void *)&cmd_set_vf_rxmode_vf, 8380 (void *)&cmd_set_vf_rxmode_vfid, 8381 (void *)&cmd_set_vf_rxmode_what, 8382 (void *)&cmd_set_vf_rxmode_mode, 8383 (void *)&cmd_set_vf_rxmode_on, 8384 NULL, 8385 }, 8386 }; 8387 8388 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */ 8389 struct cmd_vf_mac_addr_result { 8390 cmdline_fixed_string_t mac_addr_cmd; 8391 cmdline_fixed_string_t what; 8392 cmdline_fixed_string_t port; 8393 uint16_t port_num; 8394 cmdline_fixed_string_t vf; 8395 uint8_t vf_num; 8396 struct rte_ether_addr address; 8397 }; 8398 8399 static void cmd_vf_mac_addr_parsed(void *parsed_result, 8400 __rte_unused struct cmdline *cl, 8401 __rte_unused void *data) 8402 { 8403 struct cmd_vf_mac_addr_result *res = parsed_result; 8404 int ret = -ENOTSUP; 8405 8406 if (strcmp(res->what, "add") != 0) 8407 return; 8408 8409 #ifdef RTE_NET_I40E 8410 if (ret == -ENOTSUP) 8411 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num, 8412 &res->address); 8413 #endif 8414 #ifdef RTE_NET_BNXT 8415 if (ret == -ENOTSUP) 8416 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address, 8417 res->vf_num); 8418 #endif 8419 8420 if(ret < 0) 8421 fprintf(stderr, "vf_mac_addr_cmd error: (%s)\n", strerror(-ret)); 8422 8423 } 8424 8425 static cmdline_parse_token_string_t cmd_vf_mac_addr_cmd = 8426 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 8427 mac_addr_cmd,"mac_addr"); 8428 static cmdline_parse_token_string_t cmd_vf_mac_addr_what = 8429 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 8430 what,"add"); 8431 static cmdline_parse_token_string_t cmd_vf_mac_addr_port = 8432 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 8433 port,"port"); 8434 static cmdline_parse_token_num_t cmd_vf_mac_addr_portnum = 8435 TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result, 8436 port_num, RTE_UINT16); 8437 static cmdline_parse_token_string_t cmd_vf_mac_addr_vf = 8438 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 8439 vf,"vf"); 8440 static cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum = 8441 TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result, 8442 vf_num, RTE_UINT8); 8443 static cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr = 8444 TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result, 8445 address); 8446 8447 static cmdline_parse_inst_t cmd_vf_mac_addr_filter = { 8448 .f = cmd_vf_mac_addr_parsed, 8449 .data = (void *)0, 8450 .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: " 8451 "Add MAC address filtering for a VF on port_id", 8452 .tokens = { 8453 (void *)&cmd_vf_mac_addr_cmd, 8454 (void *)&cmd_vf_mac_addr_what, 8455 (void *)&cmd_vf_mac_addr_port, 8456 (void *)&cmd_vf_mac_addr_portnum, 8457 (void *)&cmd_vf_mac_addr_vf, 8458 (void *)&cmd_vf_mac_addr_vfnum, 8459 (void *)&cmd_vf_mac_addr_addr, 8460 NULL, 8461 }, 8462 }; 8463 8464 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */ 8465 struct cmd_vf_rx_vlan_filter { 8466 cmdline_fixed_string_t rx_vlan; 8467 cmdline_fixed_string_t what; 8468 uint16_t vlan_id; 8469 cmdline_fixed_string_t port; 8470 portid_t port_id; 8471 cmdline_fixed_string_t vf; 8472 uint64_t vf_mask; 8473 }; 8474 8475 static void 8476 cmd_vf_rx_vlan_filter_parsed(void *parsed_result, 8477 __rte_unused struct cmdline *cl, 8478 __rte_unused void *data) 8479 { 8480 struct cmd_vf_rx_vlan_filter *res = parsed_result; 8481 int ret = -ENOTSUP; 8482 8483 __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0; 8484 8485 #ifdef RTE_NET_IXGBE 8486 if (ret == -ENOTSUP) 8487 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id, 8488 res->vlan_id, res->vf_mask, is_add); 8489 #endif 8490 #ifdef RTE_NET_I40E 8491 if (ret == -ENOTSUP) 8492 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id, 8493 res->vlan_id, res->vf_mask, is_add); 8494 #endif 8495 #ifdef RTE_NET_BNXT 8496 if (ret == -ENOTSUP) 8497 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id, 8498 res->vlan_id, res->vf_mask, is_add); 8499 #endif 8500 8501 switch (ret) { 8502 case 0: 8503 break; 8504 case -EINVAL: 8505 fprintf(stderr, "invalid vlan_id %d or vf_mask %"PRIu64"\n", 8506 res->vlan_id, res->vf_mask); 8507 break; 8508 case -ENODEV: 8509 fprintf(stderr, "invalid port_id %d\n", res->port_id); 8510 break; 8511 case -ENOTSUP: 8512 fprintf(stderr, "function not implemented or supported\n"); 8513 break; 8514 default: 8515 fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); 8516 } 8517 } 8518 8519 static cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan = 8520 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 8521 rx_vlan, "rx_vlan"); 8522 static cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what = 8523 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 8524 what, "add#rm"); 8525 static cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid = 8526 TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter, 8527 vlan_id, RTE_UINT16); 8528 static cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port = 8529 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 8530 port, "port"); 8531 static cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid = 8532 TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter, 8533 port_id, RTE_UINT16); 8534 static cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf = 8535 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 8536 vf, "vf"); 8537 static cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask = 8538 TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter, 8539 vf_mask, RTE_UINT64); 8540 8541 static cmdline_parse_inst_t cmd_vf_rxvlan_filter = { 8542 .f = cmd_vf_rx_vlan_filter_parsed, 8543 .data = NULL, 8544 .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: " 8545 "(vf_mask = hexadecimal VF mask)", 8546 .tokens = { 8547 (void *)&cmd_vf_rx_vlan_filter_rx_vlan, 8548 (void *)&cmd_vf_rx_vlan_filter_what, 8549 (void *)&cmd_vf_rx_vlan_filter_vlanid, 8550 (void *)&cmd_vf_rx_vlan_filter_port, 8551 (void *)&cmd_vf_rx_vlan_filter_portid, 8552 (void *)&cmd_vf_rx_vlan_filter_vf, 8553 (void *)&cmd_vf_rx_vlan_filter_vf_mask, 8554 NULL, 8555 }, 8556 }; 8557 8558 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */ 8559 struct cmd_queue_rate_limit_result { 8560 cmdline_fixed_string_t set; 8561 cmdline_fixed_string_t port; 8562 uint16_t port_num; 8563 cmdline_fixed_string_t queue; 8564 uint8_t queue_num; 8565 cmdline_fixed_string_t rate; 8566 uint16_t rate_num; 8567 }; 8568 8569 static void cmd_queue_rate_limit_parsed(void *parsed_result, 8570 __rte_unused struct cmdline *cl, 8571 __rte_unused void *data) 8572 { 8573 struct cmd_queue_rate_limit_result *res = parsed_result; 8574 int ret = 0; 8575 8576 if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0) 8577 && (strcmp(res->queue, "queue") == 0) 8578 && (strcmp(res->rate, "rate") == 0)) 8579 ret = set_queue_rate_limit(res->port_num, res->queue_num, 8580 res->rate_num); 8581 if (ret < 0) 8582 fprintf(stderr, "queue_rate_limit_cmd error: (%s)\n", 8583 strerror(-ret)); 8584 8585 } 8586 8587 static cmdline_parse_token_string_t cmd_queue_rate_limit_set = 8588 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 8589 set, "set"); 8590 static cmdline_parse_token_string_t cmd_queue_rate_limit_port = 8591 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 8592 port, "port"); 8593 static cmdline_parse_token_num_t cmd_queue_rate_limit_portnum = 8594 TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result, 8595 port_num, RTE_UINT16); 8596 static cmdline_parse_token_string_t cmd_queue_rate_limit_queue = 8597 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 8598 queue, "queue"); 8599 static cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum = 8600 TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result, 8601 queue_num, RTE_UINT8); 8602 static cmdline_parse_token_string_t cmd_queue_rate_limit_rate = 8603 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 8604 rate, "rate"); 8605 static cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum = 8606 TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result, 8607 rate_num, RTE_UINT16); 8608 8609 static cmdline_parse_inst_t cmd_queue_rate_limit = { 8610 .f = cmd_queue_rate_limit_parsed, 8611 .data = (void *)0, 8612 .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: " 8613 "Set rate limit for a queue on port_id", 8614 .tokens = { 8615 (void *)&cmd_queue_rate_limit_set, 8616 (void *)&cmd_queue_rate_limit_port, 8617 (void *)&cmd_queue_rate_limit_portnum, 8618 (void *)&cmd_queue_rate_limit_queue, 8619 (void *)&cmd_queue_rate_limit_queuenum, 8620 (void *)&cmd_queue_rate_limit_rate, 8621 (void *)&cmd_queue_rate_limit_ratenum, 8622 NULL, 8623 }, 8624 }; 8625 8626 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */ 8627 struct cmd_vf_rate_limit_result { 8628 cmdline_fixed_string_t set; 8629 cmdline_fixed_string_t port; 8630 uint16_t port_num; 8631 cmdline_fixed_string_t vf; 8632 uint8_t vf_num; 8633 cmdline_fixed_string_t rate; 8634 uint16_t rate_num; 8635 cmdline_fixed_string_t q_msk; 8636 uint64_t q_msk_val; 8637 }; 8638 8639 static void cmd_vf_rate_limit_parsed(void *parsed_result, 8640 __rte_unused struct cmdline *cl, 8641 __rte_unused void *data) 8642 { 8643 struct cmd_vf_rate_limit_result *res = parsed_result; 8644 int ret = 0; 8645 8646 if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0) 8647 && (strcmp(res->vf, "vf") == 0) 8648 && (strcmp(res->rate, "rate") == 0) 8649 && (strcmp(res->q_msk, "queue_mask") == 0)) 8650 ret = set_vf_rate_limit(res->port_num, res->vf_num, 8651 res->rate_num, res->q_msk_val); 8652 if (ret < 0) 8653 fprintf(stderr, "vf_rate_limit_cmd error: (%s)\n", 8654 strerror(-ret)); 8655 8656 } 8657 8658 static cmdline_parse_token_string_t cmd_vf_rate_limit_set = 8659 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 8660 set, "set"); 8661 static cmdline_parse_token_string_t cmd_vf_rate_limit_port = 8662 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 8663 port, "port"); 8664 static cmdline_parse_token_num_t cmd_vf_rate_limit_portnum = 8665 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 8666 port_num, RTE_UINT16); 8667 static cmdline_parse_token_string_t cmd_vf_rate_limit_vf = 8668 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 8669 vf, "vf"); 8670 static cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum = 8671 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 8672 vf_num, RTE_UINT8); 8673 static cmdline_parse_token_string_t cmd_vf_rate_limit_rate = 8674 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 8675 rate, "rate"); 8676 static cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum = 8677 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 8678 rate_num, RTE_UINT16); 8679 static cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk = 8680 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 8681 q_msk, "queue_mask"); 8682 static cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val = 8683 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 8684 q_msk_val, RTE_UINT64); 8685 8686 static cmdline_parse_inst_t cmd_vf_rate_limit = { 8687 .f = cmd_vf_rate_limit_parsed, 8688 .data = (void *)0, 8689 .help_str = "set port <port_id> vf <vf_id> rate <rate_value> " 8690 "queue_mask <queue_mask_value>: " 8691 "Set rate limit for queues of VF on port_id", 8692 .tokens = { 8693 (void *)&cmd_vf_rate_limit_set, 8694 (void *)&cmd_vf_rate_limit_port, 8695 (void *)&cmd_vf_rate_limit_portnum, 8696 (void *)&cmd_vf_rate_limit_vf, 8697 (void *)&cmd_vf_rate_limit_vfnum, 8698 (void *)&cmd_vf_rate_limit_rate, 8699 (void *)&cmd_vf_rate_limit_ratenum, 8700 (void *)&cmd_vf_rate_limit_q_msk, 8701 (void *)&cmd_vf_rate_limit_q_msk_val, 8702 NULL, 8703 }, 8704 }; 8705 8706 /* *** CONFIGURE TUNNEL UDP PORT *** */ 8707 struct cmd_tunnel_udp_config { 8708 cmdline_fixed_string_t rx_vxlan_port; 8709 cmdline_fixed_string_t what; 8710 uint16_t udp_port; 8711 portid_t port_id; 8712 }; 8713 8714 static void 8715 cmd_tunnel_udp_config_parsed(void *parsed_result, 8716 __rte_unused struct cmdline *cl, 8717 __rte_unused void *data) 8718 { 8719 struct cmd_tunnel_udp_config *res = parsed_result; 8720 struct rte_eth_udp_tunnel tunnel_udp; 8721 int ret; 8722 8723 tunnel_udp.udp_port = res->udp_port; 8724 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN; 8725 8726 if (!strcmp(res->what, "add")) 8727 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id, 8728 &tunnel_udp); 8729 else 8730 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id, 8731 &tunnel_udp); 8732 8733 if (ret < 0) 8734 fprintf(stderr, "udp tunneling add error: (%s)\n", 8735 strerror(-ret)); 8736 } 8737 8738 static cmdline_parse_token_string_t cmd_tunnel_udp_config_rx_vxlan_port = 8739 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config, 8740 rx_vxlan_port, "rx_vxlan_port"); 8741 static cmdline_parse_token_string_t cmd_tunnel_udp_config_what = 8742 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config, 8743 what, "add#rm"); 8744 static cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port = 8745 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config, 8746 udp_port, RTE_UINT16); 8747 static cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id = 8748 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config, 8749 port_id, RTE_UINT16); 8750 8751 static cmdline_parse_inst_t cmd_tunnel_udp_config = { 8752 .f = cmd_tunnel_udp_config_parsed, 8753 .data = (void *)0, 8754 .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: " 8755 "Add/Remove a tunneling UDP port filter", 8756 .tokens = { 8757 (void *)&cmd_tunnel_udp_config_rx_vxlan_port, 8758 (void *)&cmd_tunnel_udp_config_what, 8759 (void *)&cmd_tunnel_udp_config_udp_port, 8760 (void *)&cmd_tunnel_udp_config_port_id, 8761 NULL, 8762 }, 8763 }; 8764 8765 struct cmd_config_tunnel_udp_port { 8766 cmdline_fixed_string_t port; 8767 cmdline_fixed_string_t config; 8768 portid_t port_id; 8769 cmdline_fixed_string_t udp_tunnel_port; 8770 cmdline_fixed_string_t action; 8771 cmdline_fixed_string_t tunnel_type; 8772 uint16_t udp_port; 8773 }; 8774 8775 static void 8776 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result, 8777 __rte_unused struct cmdline *cl, 8778 __rte_unused void *data) 8779 { 8780 struct cmd_config_tunnel_udp_port *res = parsed_result; 8781 struct rte_eth_udp_tunnel tunnel_udp; 8782 int ret = 0; 8783 8784 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 8785 return; 8786 8787 tunnel_udp.udp_port = res->udp_port; 8788 8789 if (!strcmp(res->tunnel_type, "vxlan")) { 8790 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN; 8791 } else if (!strcmp(res->tunnel_type, "geneve")) { 8792 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_GENEVE; 8793 } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) { 8794 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN_GPE; 8795 } else if (!strcmp(res->tunnel_type, "ecpri")) { 8796 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_ECPRI; 8797 } else { 8798 fprintf(stderr, "Invalid tunnel type\n"); 8799 return; 8800 } 8801 8802 if (!strcmp(res->action, "add")) 8803 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id, 8804 &tunnel_udp); 8805 else 8806 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id, 8807 &tunnel_udp); 8808 8809 if (ret < 0) 8810 fprintf(stderr, "udp tunneling port add error: (%s)\n", 8811 strerror(-ret)); 8812 } 8813 8814 static cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port = 8815 TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port, 8816 "port"); 8817 static cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config = 8818 TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config, 8819 "config"); 8820 static cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id = 8821 TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id, 8822 RTE_UINT16); 8823 static cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port = 8824 TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, 8825 udp_tunnel_port, 8826 "udp_tunnel_port"); 8827 static cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action = 8828 TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action, 8829 "add#rm"); 8830 static cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type = 8831 TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type, 8832 "vxlan#geneve#vxlan-gpe#ecpri"); 8833 static cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value = 8834 TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port, 8835 RTE_UINT16); 8836 8837 static cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = { 8838 .f = cmd_cfg_tunnel_udp_port_parsed, 8839 .data = NULL, 8840 .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|" 8841 "geneve|vxlan-gpe|ecpri <udp_port>", 8842 .tokens = { 8843 (void *)&cmd_config_tunnel_udp_port_port, 8844 (void *)&cmd_config_tunnel_udp_port_config, 8845 (void *)&cmd_config_tunnel_udp_port_port_id, 8846 (void *)&cmd_config_tunnel_udp_port_tunnel_port, 8847 (void *)&cmd_config_tunnel_udp_port_action, 8848 (void *)&cmd_config_tunnel_udp_port_tunnel_type, 8849 (void *)&cmd_config_tunnel_udp_port_value, 8850 NULL, 8851 }, 8852 }; 8853 8854 /* ******************************************************************************** */ 8855 8856 struct cmd_dump_result { 8857 cmdline_fixed_string_t dump; 8858 }; 8859 8860 static void 8861 dump_struct_sizes(void) 8862 { 8863 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t)); 8864 DUMP_SIZE(struct rte_mbuf); 8865 DUMP_SIZE(struct rte_mempool); 8866 DUMP_SIZE(struct rte_ring); 8867 #undef DUMP_SIZE 8868 } 8869 8870 8871 /* Dump the socket memory statistics on console */ 8872 static void 8873 dump_socket_mem(FILE *f) 8874 { 8875 struct rte_malloc_socket_stats socket_stats; 8876 unsigned int i; 8877 size_t total = 0; 8878 size_t alloc = 0; 8879 size_t free = 0; 8880 unsigned int n_alloc = 0; 8881 unsigned int n_free = 0; 8882 static size_t last_allocs; 8883 static size_t last_total; 8884 8885 8886 for (i = 0; i < RTE_MAX_NUMA_NODES; i++) { 8887 if (rte_malloc_get_socket_stats(i, &socket_stats) || 8888 !socket_stats.heap_totalsz_bytes) 8889 continue; 8890 total += socket_stats.heap_totalsz_bytes; 8891 alloc += socket_stats.heap_allocsz_bytes; 8892 free += socket_stats.heap_freesz_bytes; 8893 n_alloc += socket_stats.alloc_count; 8894 n_free += socket_stats.free_count; 8895 fprintf(f, 8896 "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n", 8897 i, 8898 (double)socket_stats.heap_totalsz_bytes / (1024 * 1024), 8899 (double)socket_stats.heap_allocsz_bytes / (1024 * 1024), 8900 (double)socket_stats.heap_allocsz_bytes * 100 / 8901 (double)socket_stats.heap_totalsz_bytes, 8902 (double)socket_stats.heap_freesz_bytes / (1024 * 1024), 8903 socket_stats.alloc_count, 8904 socket_stats.free_count); 8905 } 8906 fprintf(f, 8907 "Total : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n", 8908 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024), 8909 total ? ((double)alloc * 100 / (double)total) : 0, 8910 (double)free / (1024 * 1024), 8911 n_alloc, n_free); 8912 if (last_allocs) 8913 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n", 8914 ((double)total - (double)last_total) / (1024 * 1024), 8915 (double)(alloc - (double)last_allocs) / 1024 / 1024); 8916 last_allocs = alloc; 8917 last_total = total; 8918 } 8919 8920 static void cmd_dump_parsed(void *parsed_result, 8921 __rte_unused struct cmdline *cl, 8922 __rte_unused void *data) 8923 { 8924 struct cmd_dump_result *res = parsed_result; 8925 8926 if (!strcmp(res->dump, "dump_physmem")) 8927 rte_dump_physmem_layout(stdout); 8928 else if (!strcmp(res->dump, "dump_socket_mem")) 8929 dump_socket_mem(stdout); 8930 else if (!strcmp(res->dump, "dump_memzone")) 8931 rte_memzone_dump(stdout); 8932 else if (!strcmp(res->dump, "dump_struct_sizes")) 8933 dump_struct_sizes(); 8934 else if (!strcmp(res->dump, "dump_ring")) 8935 rte_ring_list_dump(stdout); 8936 else if (!strcmp(res->dump, "dump_mempool")) 8937 rte_mempool_list_dump(stdout); 8938 else if (!strcmp(res->dump, "dump_devargs")) 8939 rte_devargs_dump(stdout); 8940 else if (!strcmp(res->dump, "dump_log_types")) 8941 rte_log_dump(stdout); 8942 } 8943 8944 static cmdline_parse_token_string_t cmd_dump_dump = 8945 TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump, 8946 "dump_physmem#" 8947 "dump_memzone#" 8948 "dump_socket_mem#" 8949 "dump_struct_sizes#" 8950 "dump_ring#" 8951 "dump_mempool#" 8952 "dump_devargs#" 8953 "dump_log_types"); 8954 8955 static cmdline_parse_inst_t cmd_dump = { 8956 .f = cmd_dump_parsed, /* function to call */ 8957 .data = NULL, /* 2nd arg of func */ 8958 .help_str = "Dump status", 8959 .tokens = { /* token list, NULL terminated */ 8960 (void *)&cmd_dump_dump, 8961 NULL, 8962 }, 8963 }; 8964 8965 /* ******************************************************************************** */ 8966 8967 struct cmd_dump_one_result { 8968 cmdline_fixed_string_t dump; 8969 cmdline_fixed_string_t name; 8970 }; 8971 8972 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl, 8973 __rte_unused void *data) 8974 { 8975 struct cmd_dump_one_result *res = parsed_result; 8976 8977 if (!strcmp(res->dump, "dump_ring")) { 8978 struct rte_ring *r; 8979 r = rte_ring_lookup(res->name); 8980 if (r == NULL) { 8981 cmdline_printf(cl, "Cannot find ring\n"); 8982 return; 8983 } 8984 rte_ring_dump(stdout, r); 8985 } else if (!strcmp(res->dump, "dump_mempool")) { 8986 struct rte_mempool *mp; 8987 mp = rte_mempool_lookup(res->name); 8988 if (mp == NULL) { 8989 cmdline_printf(cl, "Cannot find mempool\n"); 8990 return; 8991 } 8992 rte_mempool_dump(stdout, mp); 8993 } 8994 } 8995 8996 static cmdline_parse_token_string_t cmd_dump_one_dump = 8997 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump, 8998 "dump_ring#dump_mempool"); 8999 9000 static cmdline_parse_token_string_t cmd_dump_one_name = 9001 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL); 9002 9003 static cmdline_parse_inst_t cmd_dump_one = { 9004 .f = cmd_dump_one_parsed, /* function to call */ 9005 .data = NULL, /* 2nd arg of func */ 9006 .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool", 9007 .tokens = { /* token list, NULL terminated */ 9008 (void *)&cmd_dump_one_dump, 9009 (void *)&cmd_dump_one_name, 9010 NULL, 9011 }, 9012 }; 9013 9014 /* *** Filters Control *** */ 9015 9016 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \ 9017 do { \ 9018 if ((ip_addr).family == AF_INET) \ 9019 (ip) = (ip_addr).addr.ipv4.s_addr; \ 9020 else { \ 9021 fprintf(stderr, "invalid parameter.\n"); \ 9022 return; \ 9023 } \ 9024 } while (0) 9025 9026 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \ 9027 do { \ 9028 if ((ip_addr).family == AF_INET6) \ 9029 rte_memcpy(&(ip), \ 9030 &((ip_addr).addr.ipv6), \ 9031 sizeof(struct in6_addr)); \ 9032 else { \ 9033 fprintf(stderr, "invalid parameter.\n"); \ 9034 return; \ 9035 } \ 9036 } while (0) 9037 9038 /* *** deal with flow director mask *** */ 9039 struct cmd_flow_director_mask_result { 9040 cmdline_fixed_string_t flow_director_mask; 9041 portid_t port_id; 9042 cmdline_fixed_string_t mode; 9043 cmdline_fixed_string_t mode_value; 9044 cmdline_fixed_string_t vlan; 9045 uint16_t vlan_mask; 9046 cmdline_fixed_string_t src_mask; 9047 cmdline_ipaddr_t ipv4_src; 9048 cmdline_ipaddr_t ipv6_src; 9049 uint16_t port_src; 9050 cmdline_fixed_string_t dst_mask; 9051 cmdline_ipaddr_t ipv4_dst; 9052 cmdline_ipaddr_t ipv6_dst; 9053 uint16_t port_dst; 9054 cmdline_fixed_string_t mac; 9055 uint8_t mac_addr_byte_mask; 9056 cmdline_fixed_string_t tunnel_id; 9057 uint32_t tunnel_id_mask; 9058 cmdline_fixed_string_t tunnel_type; 9059 uint8_t tunnel_type_mask; 9060 }; 9061 9062 static void 9063 cmd_flow_director_mask_parsed(void *parsed_result, 9064 __rte_unused struct cmdline *cl, 9065 __rte_unused void *data) 9066 { 9067 struct cmd_flow_director_mask_result *res = parsed_result; 9068 struct rte_eth_fdir_masks *mask; 9069 struct rte_port *port; 9070 9071 port = &ports[res->port_id]; 9072 /** Check if the port is not started **/ 9073 if (port->port_status != RTE_PORT_STOPPED) { 9074 fprintf(stderr, "Please stop port %d first\n", res->port_id); 9075 return; 9076 } 9077 9078 mask = &port->dev_conf.fdir_conf.mask; 9079 9080 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) { 9081 if (strcmp(res->mode_value, "MAC-VLAN")) { 9082 fprintf(stderr, "Please set mode to MAC-VLAN.\n"); 9083 return; 9084 } 9085 9086 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask); 9087 } else if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL) { 9088 if (strcmp(res->mode_value, "Tunnel")) { 9089 fprintf(stderr, "Please set mode to Tunnel.\n"); 9090 return; 9091 } 9092 9093 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask); 9094 mask->mac_addr_byte_mask = res->mac_addr_byte_mask; 9095 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask); 9096 mask->tunnel_type_mask = res->tunnel_type_mask; 9097 } else { 9098 if (strcmp(res->mode_value, "IP")) { 9099 fprintf(stderr, "Please set mode to IP.\n"); 9100 return; 9101 } 9102 9103 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask); 9104 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip); 9105 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip); 9106 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip); 9107 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip); 9108 mask->src_port_mask = rte_cpu_to_be_16(res->port_src); 9109 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst); 9110 } 9111 9112 cmd_reconfig_device_queue(res->port_id, 1, 1); 9113 } 9114 9115 static cmdline_parse_token_string_t cmd_flow_director_mask = 9116 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9117 flow_director_mask, "flow_director_mask"); 9118 static cmdline_parse_token_num_t cmd_flow_director_mask_port_id = 9119 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9120 port_id, RTE_UINT16); 9121 static cmdline_parse_token_string_t cmd_flow_director_mask_vlan = 9122 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9123 vlan, "vlan"); 9124 static cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value = 9125 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9126 vlan_mask, RTE_UINT16); 9127 static cmdline_parse_token_string_t cmd_flow_director_mask_src = 9128 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9129 src_mask, "src_mask"); 9130 static cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src = 9131 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 9132 ipv4_src); 9133 static cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src = 9134 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 9135 ipv6_src); 9136 static cmdline_parse_token_num_t cmd_flow_director_mask_port_src = 9137 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9138 port_src, RTE_UINT16); 9139 static cmdline_parse_token_string_t cmd_flow_director_mask_dst = 9140 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9141 dst_mask, "dst_mask"); 9142 static cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst = 9143 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 9144 ipv4_dst); 9145 static cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst = 9146 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 9147 ipv6_dst); 9148 static cmdline_parse_token_num_t cmd_flow_director_mask_port_dst = 9149 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9150 port_dst, RTE_UINT16); 9151 9152 static cmdline_parse_token_string_t cmd_flow_director_mask_mode = 9153 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9154 mode, "mode"); 9155 static cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip = 9156 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9157 mode_value, "IP"); 9158 static cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan = 9159 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9160 mode_value, "MAC-VLAN"); 9161 static cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel = 9162 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9163 mode_value, "Tunnel"); 9164 static cmdline_parse_token_string_t cmd_flow_director_mask_mac = 9165 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9166 mac, "mac"); 9167 static cmdline_parse_token_num_t cmd_flow_director_mask_mac_value = 9168 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9169 mac_addr_byte_mask, RTE_UINT8); 9170 static cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type = 9171 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9172 tunnel_type, "tunnel-type"); 9173 static cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value = 9174 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9175 tunnel_type_mask, RTE_UINT8); 9176 static cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id = 9177 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9178 tunnel_id, "tunnel-id"); 9179 static cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value = 9180 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9181 tunnel_id_mask, RTE_UINT32); 9182 9183 static cmdline_parse_inst_t cmd_set_flow_director_ip_mask = { 9184 .f = cmd_flow_director_mask_parsed, 9185 .data = NULL, 9186 .help_str = "flow_director_mask ... : " 9187 "Set IP mode flow director's mask on NIC", 9188 .tokens = { 9189 (void *)&cmd_flow_director_mask, 9190 (void *)&cmd_flow_director_mask_port_id, 9191 (void *)&cmd_flow_director_mask_mode, 9192 (void *)&cmd_flow_director_mask_mode_ip, 9193 (void *)&cmd_flow_director_mask_vlan, 9194 (void *)&cmd_flow_director_mask_vlan_value, 9195 (void *)&cmd_flow_director_mask_src, 9196 (void *)&cmd_flow_director_mask_ipv4_src, 9197 (void *)&cmd_flow_director_mask_ipv6_src, 9198 (void *)&cmd_flow_director_mask_port_src, 9199 (void *)&cmd_flow_director_mask_dst, 9200 (void *)&cmd_flow_director_mask_ipv4_dst, 9201 (void *)&cmd_flow_director_mask_ipv6_dst, 9202 (void *)&cmd_flow_director_mask_port_dst, 9203 NULL, 9204 }, 9205 }; 9206 9207 static cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = { 9208 .f = cmd_flow_director_mask_parsed, 9209 .data = NULL, 9210 .help_str = "flow_director_mask ... : Set MAC VLAN mode " 9211 "flow director's mask on NIC", 9212 .tokens = { 9213 (void *)&cmd_flow_director_mask, 9214 (void *)&cmd_flow_director_mask_port_id, 9215 (void *)&cmd_flow_director_mask_mode, 9216 (void *)&cmd_flow_director_mask_mode_mac_vlan, 9217 (void *)&cmd_flow_director_mask_vlan, 9218 (void *)&cmd_flow_director_mask_vlan_value, 9219 NULL, 9220 }, 9221 }; 9222 9223 static cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = { 9224 .f = cmd_flow_director_mask_parsed, 9225 .data = NULL, 9226 .help_str = "flow_director_mask ... : Set tunnel mode " 9227 "flow director's mask on NIC", 9228 .tokens = { 9229 (void *)&cmd_flow_director_mask, 9230 (void *)&cmd_flow_director_mask_port_id, 9231 (void *)&cmd_flow_director_mask_mode, 9232 (void *)&cmd_flow_director_mask_mode_tunnel, 9233 (void *)&cmd_flow_director_mask_vlan, 9234 (void *)&cmd_flow_director_mask_vlan_value, 9235 (void *)&cmd_flow_director_mask_mac, 9236 (void *)&cmd_flow_director_mask_mac_value, 9237 (void *)&cmd_flow_director_mask_tunnel_type, 9238 (void *)&cmd_flow_director_mask_tunnel_type_value, 9239 (void *)&cmd_flow_director_mask_tunnel_id, 9240 (void *)&cmd_flow_director_mask_tunnel_id_value, 9241 NULL, 9242 }, 9243 }; 9244 9245 /* *** deal with flow director flexible payload configuration *** */ 9246 struct cmd_flow_director_flexpayload_result { 9247 cmdline_fixed_string_t flow_director_flexpayload; 9248 portid_t port_id; 9249 cmdline_fixed_string_t payload_layer; 9250 cmdline_fixed_string_t payload_cfg; 9251 }; 9252 9253 static inline int 9254 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num) 9255 { 9256 char s[256]; 9257 const char *p, *p0 = q_arg; 9258 char *end; 9259 unsigned long int_fld; 9260 char *str_fld[max_num]; 9261 int i; 9262 unsigned size; 9263 int ret = -1; 9264 9265 p = strchr(p0, '('); 9266 if (p == NULL) 9267 return -1; 9268 ++p; 9269 p0 = strchr(p, ')'); 9270 if (p0 == NULL) 9271 return -1; 9272 9273 size = p0 - p; 9274 if (size >= sizeof(s)) 9275 return -1; 9276 9277 snprintf(s, sizeof(s), "%.*s", size, p); 9278 ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ','); 9279 if (ret < 0 || ret > max_num) 9280 return -1; 9281 for (i = 0; i < ret; i++) { 9282 errno = 0; 9283 int_fld = strtoul(str_fld[i], &end, 0); 9284 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX) 9285 return -1; 9286 offsets[i] = (uint16_t)int_fld; 9287 } 9288 return ret; 9289 } 9290 9291 static void 9292 cmd_flow_director_flxpld_parsed(void *parsed_result, 9293 __rte_unused struct cmdline *cl, 9294 __rte_unused void *data) 9295 { 9296 struct cmd_flow_director_flexpayload_result *res = parsed_result; 9297 struct rte_eth_flex_payload_cfg flex_cfg; 9298 struct rte_port *port; 9299 int ret = 0; 9300 9301 port = &ports[res->port_id]; 9302 /** Check if the port is not started **/ 9303 if (port->port_status != RTE_PORT_STOPPED) { 9304 fprintf(stderr, "Please stop port %d first\n", res->port_id); 9305 return; 9306 } 9307 9308 memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg)); 9309 9310 if (!strcmp(res->payload_layer, "raw")) 9311 flex_cfg.type = RTE_ETH_RAW_PAYLOAD; 9312 else if (!strcmp(res->payload_layer, "l2")) 9313 flex_cfg.type = RTE_ETH_L2_PAYLOAD; 9314 else if (!strcmp(res->payload_layer, "l3")) 9315 flex_cfg.type = RTE_ETH_L3_PAYLOAD; 9316 else if (!strcmp(res->payload_layer, "l4")) 9317 flex_cfg.type = RTE_ETH_L4_PAYLOAD; 9318 9319 ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset, 9320 RTE_ETH_FDIR_MAX_FLEXLEN); 9321 if (ret < 0) { 9322 fprintf(stderr, "error: Cannot parse flex payload input.\n"); 9323 return; 9324 } 9325 9326 fdir_set_flex_payload(res->port_id, &flex_cfg); 9327 cmd_reconfig_device_queue(res->port_id, 1, 1); 9328 } 9329 9330 static cmdline_parse_token_string_t cmd_flow_director_flexpayload = 9331 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result, 9332 flow_director_flexpayload, 9333 "flow_director_flex_payload"); 9334 static cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id = 9335 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result, 9336 port_id, RTE_UINT16); 9337 static cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer = 9338 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result, 9339 payload_layer, "raw#l2#l3#l4"); 9340 static cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg = 9341 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result, 9342 payload_cfg, NULL); 9343 9344 static cmdline_parse_inst_t cmd_set_flow_director_flex_payload = { 9345 .f = cmd_flow_director_flxpld_parsed, 9346 .data = NULL, 9347 .help_str = "flow_director_flexpayload ... : " 9348 "Set flow director's flex payload on NIC", 9349 .tokens = { 9350 (void *)&cmd_flow_director_flexpayload, 9351 (void *)&cmd_flow_director_flexpayload_port_id, 9352 (void *)&cmd_flow_director_flexpayload_payload_layer, 9353 (void *)&cmd_flow_director_flexpayload_payload_cfg, 9354 NULL, 9355 }, 9356 }; 9357 9358 /* Generic flow interface command. */ 9359 extern cmdline_parse_inst_t cmd_flow; 9360 9361 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */ 9362 struct cmd_mcast_addr_result { 9363 cmdline_fixed_string_t mcast_addr_cmd; 9364 cmdline_fixed_string_t what; 9365 uint16_t port_num; 9366 struct rte_ether_addr mc_addr; 9367 }; 9368 9369 static void cmd_mcast_addr_parsed(void *parsed_result, 9370 __rte_unused struct cmdline *cl, 9371 __rte_unused void *data) 9372 { 9373 struct cmd_mcast_addr_result *res = parsed_result; 9374 9375 if (!rte_is_multicast_ether_addr(&res->mc_addr)) { 9376 fprintf(stderr, 9377 "Invalid multicast addr " RTE_ETHER_ADDR_PRT_FMT "\n", 9378 RTE_ETHER_ADDR_BYTES(&res->mc_addr)); 9379 return; 9380 } 9381 if (strcmp(res->what, "add") == 0) 9382 mcast_addr_add(res->port_num, &res->mc_addr); 9383 else 9384 mcast_addr_remove(res->port_num, &res->mc_addr); 9385 } 9386 9387 static cmdline_parse_token_string_t cmd_mcast_addr_cmd = 9388 TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, 9389 mcast_addr_cmd, "mcast_addr"); 9390 static cmdline_parse_token_string_t cmd_mcast_addr_what = 9391 TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what, 9392 "add#remove"); 9393 static cmdline_parse_token_num_t cmd_mcast_addr_portnum = 9394 TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, 9395 RTE_UINT16); 9396 static cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr = 9397 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address); 9398 9399 static cmdline_parse_inst_t cmd_mcast_addr = { 9400 .f = cmd_mcast_addr_parsed, 9401 .data = (void *)0, 9402 .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: " 9403 "Add/Remove multicast MAC address on port_id", 9404 .tokens = { 9405 (void *)&cmd_mcast_addr_cmd, 9406 (void *)&cmd_mcast_addr_what, 9407 (void *)&cmd_mcast_addr_portnum, 9408 (void *)&cmd_mcast_addr_addr, 9409 NULL, 9410 }, 9411 }; 9412 9413 /* vf vlan anti spoof configuration */ 9414 9415 /* Common result structure for vf vlan anti spoof */ 9416 struct cmd_vf_vlan_anti_spoof_result { 9417 cmdline_fixed_string_t set; 9418 cmdline_fixed_string_t vf; 9419 cmdline_fixed_string_t vlan; 9420 cmdline_fixed_string_t antispoof; 9421 portid_t port_id; 9422 uint32_t vf_id; 9423 cmdline_fixed_string_t on_off; 9424 }; 9425 9426 /* Common CLI fields for vf vlan anti spoof enable disable */ 9427 static cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set = 9428 TOKEN_STRING_INITIALIZER 9429 (struct cmd_vf_vlan_anti_spoof_result, 9430 set, "set"); 9431 static cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf = 9432 TOKEN_STRING_INITIALIZER 9433 (struct cmd_vf_vlan_anti_spoof_result, 9434 vf, "vf"); 9435 static cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan = 9436 TOKEN_STRING_INITIALIZER 9437 (struct cmd_vf_vlan_anti_spoof_result, 9438 vlan, "vlan"); 9439 static cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof = 9440 TOKEN_STRING_INITIALIZER 9441 (struct cmd_vf_vlan_anti_spoof_result, 9442 antispoof, "antispoof"); 9443 static cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id = 9444 TOKEN_NUM_INITIALIZER 9445 (struct cmd_vf_vlan_anti_spoof_result, 9446 port_id, RTE_UINT16); 9447 static cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id = 9448 TOKEN_NUM_INITIALIZER 9449 (struct cmd_vf_vlan_anti_spoof_result, 9450 vf_id, RTE_UINT32); 9451 static cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off = 9452 TOKEN_STRING_INITIALIZER 9453 (struct cmd_vf_vlan_anti_spoof_result, 9454 on_off, "on#off"); 9455 9456 static void 9457 cmd_set_vf_vlan_anti_spoof_parsed( 9458 void *parsed_result, 9459 __rte_unused struct cmdline *cl, 9460 __rte_unused void *data) 9461 { 9462 struct cmd_vf_vlan_anti_spoof_result *res = parsed_result; 9463 int ret = -ENOTSUP; 9464 9465 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 9466 9467 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 9468 return; 9469 9470 #ifdef RTE_NET_IXGBE 9471 if (ret == -ENOTSUP) 9472 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id, 9473 res->vf_id, is_on); 9474 #endif 9475 #ifdef RTE_NET_I40E 9476 if (ret == -ENOTSUP) 9477 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id, 9478 res->vf_id, is_on); 9479 #endif 9480 #ifdef RTE_NET_BNXT 9481 if (ret == -ENOTSUP) 9482 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id, 9483 res->vf_id, is_on); 9484 #endif 9485 9486 switch (ret) { 9487 case 0: 9488 break; 9489 case -EINVAL: 9490 fprintf(stderr, "invalid vf_id %d\n", res->vf_id); 9491 break; 9492 case -ENODEV: 9493 fprintf(stderr, "invalid port_id %d\n", res->port_id); 9494 break; 9495 case -ENOTSUP: 9496 fprintf(stderr, "function not implemented\n"); 9497 break; 9498 default: 9499 fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); 9500 } 9501 } 9502 9503 static cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = { 9504 .f = cmd_set_vf_vlan_anti_spoof_parsed, 9505 .data = NULL, 9506 .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off", 9507 .tokens = { 9508 (void *)&cmd_vf_vlan_anti_spoof_set, 9509 (void *)&cmd_vf_vlan_anti_spoof_vf, 9510 (void *)&cmd_vf_vlan_anti_spoof_vlan, 9511 (void *)&cmd_vf_vlan_anti_spoof_antispoof, 9512 (void *)&cmd_vf_vlan_anti_spoof_port_id, 9513 (void *)&cmd_vf_vlan_anti_spoof_vf_id, 9514 (void *)&cmd_vf_vlan_anti_spoof_on_off, 9515 NULL, 9516 }, 9517 }; 9518 9519 /* vf mac anti spoof configuration */ 9520 9521 /* Common result structure for vf mac anti spoof */ 9522 struct cmd_vf_mac_anti_spoof_result { 9523 cmdline_fixed_string_t set; 9524 cmdline_fixed_string_t vf; 9525 cmdline_fixed_string_t mac; 9526 cmdline_fixed_string_t antispoof; 9527 portid_t port_id; 9528 uint32_t vf_id; 9529 cmdline_fixed_string_t on_off; 9530 }; 9531 9532 /* Common CLI fields for vf mac anti spoof enable disable */ 9533 static cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set = 9534 TOKEN_STRING_INITIALIZER 9535 (struct cmd_vf_mac_anti_spoof_result, 9536 set, "set"); 9537 static cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf = 9538 TOKEN_STRING_INITIALIZER 9539 (struct cmd_vf_mac_anti_spoof_result, 9540 vf, "vf"); 9541 static cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac = 9542 TOKEN_STRING_INITIALIZER 9543 (struct cmd_vf_mac_anti_spoof_result, 9544 mac, "mac"); 9545 static cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof = 9546 TOKEN_STRING_INITIALIZER 9547 (struct cmd_vf_mac_anti_spoof_result, 9548 antispoof, "antispoof"); 9549 static cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id = 9550 TOKEN_NUM_INITIALIZER 9551 (struct cmd_vf_mac_anti_spoof_result, 9552 port_id, RTE_UINT16); 9553 static cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id = 9554 TOKEN_NUM_INITIALIZER 9555 (struct cmd_vf_mac_anti_spoof_result, 9556 vf_id, RTE_UINT32); 9557 static cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off = 9558 TOKEN_STRING_INITIALIZER 9559 (struct cmd_vf_mac_anti_spoof_result, 9560 on_off, "on#off"); 9561 9562 static void 9563 cmd_set_vf_mac_anti_spoof_parsed( 9564 void *parsed_result, 9565 __rte_unused struct cmdline *cl, 9566 __rte_unused void *data) 9567 { 9568 struct cmd_vf_mac_anti_spoof_result *res = parsed_result; 9569 int ret = -ENOTSUP; 9570 9571 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 9572 9573 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 9574 return; 9575 9576 #ifdef RTE_NET_IXGBE 9577 if (ret == -ENOTSUP) 9578 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id, 9579 res->vf_id, is_on); 9580 #endif 9581 #ifdef RTE_NET_I40E 9582 if (ret == -ENOTSUP) 9583 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id, 9584 res->vf_id, is_on); 9585 #endif 9586 #ifdef RTE_NET_BNXT 9587 if (ret == -ENOTSUP) 9588 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id, 9589 res->vf_id, is_on); 9590 #endif 9591 9592 switch (ret) { 9593 case 0: 9594 break; 9595 case -EINVAL: 9596 fprintf(stderr, "invalid vf_id %d or is_on %d\n", 9597 res->vf_id, is_on); 9598 break; 9599 case -ENODEV: 9600 fprintf(stderr, "invalid port_id %d\n", res->port_id); 9601 break; 9602 case -ENOTSUP: 9603 fprintf(stderr, "function not implemented\n"); 9604 break; 9605 default: 9606 fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); 9607 } 9608 } 9609 9610 static cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = { 9611 .f = cmd_set_vf_mac_anti_spoof_parsed, 9612 .data = NULL, 9613 .help_str = "set vf mac antispoof <port_id> <vf_id> on|off", 9614 .tokens = { 9615 (void *)&cmd_vf_mac_anti_spoof_set, 9616 (void *)&cmd_vf_mac_anti_spoof_vf, 9617 (void *)&cmd_vf_mac_anti_spoof_mac, 9618 (void *)&cmd_vf_mac_anti_spoof_antispoof, 9619 (void *)&cmd_vf_mac_anti_spoof_port_id, 9620 (void *)&cmd_vf_mac_anti_spoof_vf_id, 9621 (void *)&cmd_vf_mac_anti_spoof_on_off, 9622 NULL, 9623 }, 9624 }; 9625 9626 /* vf vlan strip queue configuration */ 9627 9628 /* Common result structure for vf mac anti spoof */ 9629 struct cmd_vf_vlan_stripq_result { 9630 cmdline_fixed_string_t set; 9631 cmdline_fixed_string_t vf; 9632 cmdline_fixed_string_t vlan; 9633 cmdline_fixed_string_t stripq; 9634 portid_t port_id; 9635 uint16_t vf_id; 9636 cmdline_fixed_string_t on_off; 9637 }; 9638 9639 /* Common CLI fields for vf vlan strip enable disable */ 9640 static cmdline_parse_token_string_t cmd_vf_vlan_stripq_set = 9641 TOKEN_STRING_INITIALIZER 9642 (struct cmd_vf_vlan_stripq_result, 9643 set, "set"); 9644 static cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf = 9645 TOKEN_STRING_INITIALIZER 9646 (struct cmd_vf_vlan_stripq_result, 9647 vf, "vf"); 9648 static cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan = 9649 TOKEN_STRING_INITIALIZER 9650 (struct cmd_vf_vlan_stripq_result, 9651 vlan, "vlan"); 9652 static cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq = 9653 TOKEN_STRING_INITIALIZER 9654 (struct cmd_vf_vlan_stripq_result, 9655 stripq, "stripq"); 9656 static cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id = 9657 TOKEN_NUM_INITIALIZER 9658 (struct cmd_vf_vlan_stripq_result, 9659 port_id, RTE_UINT16); 9660 static cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id = 9661 TOKEN_NUM_INITIALIZER 9662 (struct cmd_vf_vlan_stripq_result, 9663 vf_id, RTE_UINT16); 9664 static cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off = 9665 TOKEN_STRING_INITIALIZER 9666 (struct cmd_vf_vlan_stripq_result, 9667 on_off, "on#off"); 9668 9669 static void 9670 cmd_set_vf_vlan_stripq_parsed( 9671 void *parsed_result, 9672 __rte_unused struct cmdline *cl, 9673 __rte_unused void *data) 9674 { 9675 struct cmd_vf_vlan_stripq_result *res = parsed_result; 9676 int ret = -ENOTSUP; 9677 9678 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 9679 9680 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 9681 return; 9682 9683 #ifdef RTE_NET_IXGBE 9684 if (ret == -ENOTSUP) 9685 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id, 9686 res->vf_id, is_on); 9687 #endif 9688 #ifdef RTE_NET_I40E 9689 if (ret == -ENOTSUP) 9690 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id, 9691 res->vf_id, is_on); 9692 #endif 9693 #ifdef RTE_NET_BNXT 9694 if (ret == -ENOTSUP) 9695 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id, 9696 res->vf_id, is_on); 9697 #endif 9698 9699 switch (ret) { 9700 case 0: 9701 break; 9702 case -EINVAL: 9703 fprintf(stderr, "invalid vf_id %d or is_on %d\n", 9704 res->vf_id, is_on); 9705 break; 9706 case -ENODEV: 9707 fprintf(stderr, "invalid port_id %d\n", res->port_id); 9708 break; 9709 case -ENOTSUP: 9710 fprintf(stderr, "function not implemented\n"); 9711 break; 9712 default: 9713 fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); 9714 } 9715 } 9716 9717 static cmdline_parse_inst_t cmd_set_vf_vlan_stripq = { 9718 .f = cmd_set_vf_vlan_stripq_parsed, 9719 .data = NULL, 9720 .help_str = "set vf vlan stripq <port_id> <vf_id> on|off", 9721 .tokens = { 9722 (void *)&cmd_vf_vlan_stripq_set, 9723 (void *)&cmd_vf_vlan_stripq_vf, 9724 (void *)&cmd_vf_vlan_stripq_vlan, 9725 (void *)&cmd_vf_vlan_stripq_stripq, 9726 (void *)&cmd_vf_vlan_stripq_port_id, 9727 (void *)&cmd_vf_vlan_stripq_vf_id, 9728 (void *)&cmd_vf_vlan_stripq_on_off, 9729 NULL, 9730 }, 9731 }; 9732 9733 /* vf vlan insert configuration */ 9734 9735 /* Common result structure for vf vlan insert */ 9736 struct cmd_vf_vlan_insert_result { 9737 cmdline_fixed_string_t set; 9738 cmdline_fixed_string_t vf; 9739 cmdline_fixed_string_t vlan; 9740 cmdline_fixed_string_t insert; 9741 portid_t port_id; 9742 uint16_t vf_id; 9743 uint16_t vlan_id; 9744 }; 9745 9746 /* Common CLI fields for vf vlan insert enable disable */ 9747 static cmdline_parse_token_string_t cmd_vf_vlan_insert_set = 9748 TOKEN_STRING_INITIALIZER 9749 (struct cmd_vf_vlan_insert_result, 9750 set, "set"); 9751 static cmdline_parse_token_string_t cmd_vf_vlan_insert_vf = 9752 TOKEN_STRING_INITIALIZER 9753 (struct cmd_vf_vlan_insert_result, 9754 vf, "vf"); 9755 static cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan = 9756 TOKEN_STRING_INITIALIZER 9757 (struct cmd_vf_vlan_insert_result, 9758 vlan, "vlan"); 9759 static cmdline_parse_token_string_t cmd_vf_vlan_insert_insert = 9760 TOKEN_STRING_INITIALIZER 9761 (struct cmd_vf_vlan_insert_result, 9762 insert, "insert"); 9763 static cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id = 9764 TOKEN_NUM_INITIALIZER 9765 (struct cmd_vf_vlan_insert_result, 9766 port_id, RTE_UINT16); 9767 static cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id = 9768 TOKEN_NUM_INITIALIZER 9769 (struct cmd_vf_vlan_insert_result, 9770 vf_id, RTE_UINT16); 9771 static cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id = 9772 TOKEN_NUM_INITIALIZER 9773 (struct cmd_vf_vlan_insert_result, 9774 vlan_id, RTE_UINT16); 9775 9776 static void 9777 cmd_set_vf_vlan_insert_parsed( 9778 void *parsed_result, 9779 __rte_unused struct cmdline *cl, 9780 __rte_unused void *data) 9781 { 9782 struct cmd_vf_vlan_insert_result *res = parsed_result; 9783 int ret = -ENOTSUP; 9784 9785 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 9786 return; 9787 9788 #ifdef RTE_NET_IXGBE 9789 if (ret == -ENOTSUP) 9790 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id, 9791 res->vlan_id); 9792 #endif 9793 #ifdef RTE_NET_I40E 9794 if (ret == -ENOTSUP) 9795 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id, 9796 res->vlan_id); 9797 #endif 9798 #ifdef RTE_NET_BNXT 9799 if (ret == -ENOTSUP) 9800 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id, 9801 res->vlan_id); 9802 #endif 9803 9804 switch (ret) { 9805 case 0: 9806 break; 9807 case -EINVAL: 9808 fprintf(stderr, "invalid vf_id %d or vlan_id %d\n", 9809 res->vf_id, res->vlan_id); 9810 break; 9811 case -ENODEV: 9812 fprintf(stderr, "invalid port_id %d\n", res->port_id); 9813 break; 9814 case -ENOTSUP: 9815 fprintf(stderr, "function not implemented\n"); 9816 break; 9817 default: 9818 fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); 9819 } 9820 } 9821 9822 static cmdline_parse_inst_t cmd_set_vf_vlan_insert = { 9823 .f = cmd_set_vf_vlan_insert_parsed, 9824 .data = NULL, 9825 .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>", 9826 .tokens = { 9827 (void *)&cmd_vf_vlan_insert_set, 9828 (void *)&cmd_vf_vlan_insert_vf, 9829 (void *)&cmd_vf_vlan_insert_vlan, 9830 (void *)&cmd_vf_vlan_insert_insert, 9831 (void *)&cmd_vf_vlan_insert_port_id, 9832 (void *)&cmd_vf_vlan_insert_vf_id, 9833 (void *)&cmd_vf_vlan_insert_vlan_id, 9834 NULL, 9835 }, 9836 }; 9837 9838 /* tx loopback configuration */ 9839 9840 /* Common result structure for tx loopback */ 9841 struct cmd_tx_loopback_result { 9842 cmdline_fixed_string_t set; 9843 cmdline_fixed_string_t tx; 9844 cmdline_fixed_string_t loopback; 9845 portid_t port_id; 9846 cmdline_fixed_string_t on_off; 9847 }; 9848 9849 /* Common CLI fields for tx loopback enable disable */ 9850 static cmdline_parse_token_string_t cmd_tx_loopback_set = 9851 TOKEN_STRING_INITIALIZER 9852 (struct cmd_tx_loopback_result, 9853 set, "set"); 9854 static cmdline_parse_token_string_t cmd_tx_loopback_tx = 9855 TOKEN_STRING_INITIALIZER 9856 (struct cmd_tx_loopback_result, 9857 tx, "tx"); 9858 static cmdline_parse_token_string_t cmd_tx_loopback_loopback = 9859 TOKEN_STRING_INITIALIZER 9860 (struct cmd_tx_loopback_result, 9861 loopback, "loopback"); 9862 static cmdline_parse_token_num_t cmd_tx_loopback_port_id = 9863 TOKEN_NUM_INITIALIZER 9864 (struct cmd_tx_loopback_result, 9865 port_id, RTE_UINT16); 9866 static cmdline_parse_token_string_t cmd_tx_loopback_on_off = 9867 TOKEN_STRING_INITIALIZER 9868 (struct cmd_tx_loopback_result, 9869 on_off, "on#off"); 9870 9871 static void 9872 cmd_set_tx_loopback_parsed( 9873 void *parsed_result, 9874 __rte_unused struct cmdline *cl, 9875 __rte_unused void *data) 9876 { 9877 struct cmd_tx_loopback_result *res = parsed_result; 9878 int ret = -ENOTSUP; 9879 9880 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 9881 9882 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 9883 return; 9884 9885 #ifdef RTE_NET_IXGBE 9886 if (ret == -ENOTSUP) 9887 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on); 9888 #endif 9889 #ifdef RTE_NET_I40E 9890 if (ret == -ENOTSUP) 9891 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on); 9892 #endif 9893 #ifdef RTE_NET_BNXT 9894 if (ret == -ENOTSUP) 9895 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on); 9896 #endif 9897 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA 9898 if (ret == -ENOTSUP) 9899 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on); 9900 #endif 9901 9902 switch (ret) { 9903 case 0: 9904 break; 9905 case -EINVAL: 9906 fprintf(stderr, "invalid is_on %d\n", is_on); 9907 break; 9908 case -ENODEV: 9909 fprintf(stderr, "invalid port_id %d\n", res->port_id); 9910 break; 9911 case -ENOTSUP: 9912 fprintf(stderr, "function not implemented\n"); 9913 break; 9914 default: 9915 fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); 9916 } 9917 } 9918 9919 static cmdline_parse_inst_t cmd_set_tx_loopback = { 9920 .f = cmd_set_tx_loopback_parsed, 9921 .data = NULL, 9922 .help_str = "set tx loopback <port_id> on|off", 9923 .tokens = { 9924 (void *)&cmd_tx_loopback_set, 9925 (void *)&cmd_tx_loopback_tx, 9926 (void *)&cmd_tx_loopback_loopback, 9927 (void *)&cmd_tx_loopback_port_id, 9928 (void *)&cmd_tx_loopback_on_off, 9929 NULL, 9930 }, 9931 }; 9932 9933 /* all queues drop enable configuration */ 9934 9935 /* Common result structure for all queues drop enable */ 9936 struct cmd_all_queues_drop_en_result { 9937 cmdline_fixed_string_t set; 9938 cmdline_fixed_string_t all; 9939 cmdline_fixed_string_t queues; 9940 cmdline_fixed_string_t drop; 9941 portid_t port_id; 9942 cmdline_fixed_string_t on_off; 9943 }; 9944 9945 /* Common CLI fields for tx loopback enable disable */ 9946 static cmdline_parse_token_string_t cmd_all_queues_drop_en_set = 9947 TOKEN_STRING_INITIALIZER 9948 (struct cmd_all_queues_drop_en_result, 9949 set, "set"); 9950 static cmdline_parse_token_string_t cmd_all_queues_drop_en_all = 9951 TOKEN_STRING_INITIALIZER 9952 (struct cmd_all_queues_drop_en_result, 9953 all, "all"); 9954 static cmdline_parse_token_string_t cmd_all_queues_drop_en_queues = 9955 TOKEN_STRING_INITIALIZER 9956 (struct cmd_all_queues_drop_en_result, 9957 queues, "queues"); 9958 static cmdline_parse_token_string_t cmd_all_queues_drop_en_drop = 9959 TOKEN_STRING_INITIALIZER 9960 (struct cmd_all_queues_drop_en_result, 9961 drop, "drop"); 9962 static cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id = 9963 TOKEN_NUM_INITIALIZER 9964 (struct cmd_all_queues_drop_en_result, 9965 port_id, RTE_UINT16); 9966 static cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off = 9967 TOKEN_STRING_INITIALIZER 9968 (struct cmd_all_queues_drop_en_result, 9969 on_off, "on#off"); 9970 9971 static void 9972 cmd_set_all_queues_drop_en_parsed( 9973 void *parsed_result, 9974 __rte_unused struct cmdline *cl, 9975 __rte_unused void *data) 9976 { 9977 struct cmd_all_queues_drop_en_result *res = parsed_result; 9978 int ret = -ENOTSUP; 9979 int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 9980 9981 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 9982 return; 9983 9984 #ifdef RTE_NET_IXGBE 9985 if (ret == -ENOTSUP) 9986 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on); 9987 #endif 9988 #ifdef RTE_NET_BNXT 9989 if (ret == -ENOTSUP) 9990 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on); 9991 #endif 9992 switch (ret) { 9993 case 0: 9994 break; 9995 case -EINVAL: 9996 fprintf(stderr, "invalid is_on %d\n", is_on); 9997 break; 9998 case -ENODEV: 9999 fprintf(stderr, "invalid port_id %d\n", res->port_id); 10000 break; 10001 case -ENOTSUP: 10002 fprintf(stderr, "function not implemented\n"); 10003 break; 10004 default: 10005 fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); 10006 } 10007 } 10008 10009 static cmdline_parse_inst_t cmd_set_all_queues_drop_en = { 10010 .f = cmd_set_all_queues_drop_en_parsed, 10011 .data = NULL, 10012 .help_str = "set all queues drop <port_id> on|off", 10013 .tokens = { 10014 (void *)&cmd_all_queues_drop_en_set, 10015 (void *)&cmd_all_queues_drop_en_all, 10016 (void *)&cmd_all_queues_drop_en_queues, 10017 (void *)&cmd_all_queues_drop_en_drop, 10018 (void *)&cmd_all_queues_drop_en_port_id, 10019 (void *)&cmd_all_queues_drop_en_on_off, 10020 NULL, 10021 }, 10022 }; 10023 10024 /* vf split drop enable configuration */ 10025 10026 /* Common result structure for vf split drop enable */ 10027 struct cmd_vf_split_drop_en_result { 10028 cmdline_fixed_string_t set; 10029 cmdline_fixed_string_t vf; 10030 cmdline_fixed_string_t split; 10031 cmdline_fixed_string_t drop; 10032 portid_t port_id; 10033 uint16_t vf_id; 10034 cmdline_fixed_string_t on_off; 10035 }; 10036 10037 /* Common CLI fields for vf split drop enable disable */ 10038 static cmdline_parse_token_string_t cmd_vf_split_drop_en_set = 10039 TOKEN_STRING_INITIALIZER 10040 (struct cmd_vf_split_drop_en_result, 10041 set, "set"); 10042 static cmdline_parse_token_string_t cmd_vf_split_drop_en_vf = 10043 TOKEN_STRING_INITIALIZER 10044 (struct cmd_vf_split_drop_en_result, 10045 vf, "vf"); 10046 static cmdline_parse_token_string_t cmd_vf_split_drop_en_split = 10047 TOKEN_STRING_INITIALIZER 10048 (struct cmd_vf_split_drop_en_result, 10049 split, "split"); 10050 static cmdline_parse_token_string_t cmd_vf_split_drop_en_drop = 10051 TOKEN_STRING_INITIALIZER 10052 (struct cmd_vf_split_drop_en_result, 10053 drop, "drop"); 10054 static cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id = 10055 TOKEN_NUM_INITIALIZER 10056 (struct cmd_vf_split_drop_en_result, 10057 port_id, RTE_UINT16); 10058 static cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id = 10059 TOKEN_NUM_INITIALIZER 10060 (struct cmd_vf_split_drop_en_result, 10061 vf_id, RTE_UINT16); 10062 static cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off = 10063 TOKEN_STRING_INITIALIZER 10064 (struct cmd_vf_split_drop_en_result, 10065 on_off, "on#off"); 10066 10067 static void 10068 cmd_set_vf_split_drop_en_parsed( 10069 void *parsed_result, 10070 __rte_unused struct cmdline *cl, 10071 __rte_unused void *data) 10072 { 10073 struct cmd_vf_split_drop_en_result *res = parsed_result; 10074 int ret = -ENOTSUP; 10075 int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 10076 10077 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 10078 return; 10079 10080 #ifdef RTE_NET_IXGBE 10081 ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id, 10082 is_on); 10083 #endif 10084 switch (ret) { 10085 case 0: 10086 break; 10087 case -EINVAL: 10088 fprintf(stderr, "invalid vf_id %d or is_on %d\n", 10089 res->vf_id, is_on); 10090 break; 10091 case -ENODEV: 10092 fprintf(stderr, "invalid port_id %d\n", res->port_id); 10093 break; 10094 case -ENOTSUP: 10095 fprintf(stderr, "not supported on port %d\n", res->port_id); 10096 break; 10097 default: 10098 fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); 10099 } 10100 } 10101 10102 static cmdline_parse_inst_t cmd_set_vf_split_drop_en = { 10103 .f = cmd_set_vf_split_drop_en_parsed, 10104 .data = NULL, 10105 .help_str = "set vf split drop <port_id> <vf_id> on|off", 10106 .tokens = { 10107 (void *)&cmd_vf_split_drop_en_set, 10108 (void *)&cmd_vf_split_drop_en_vf, 10109 (void *)&cmd_vf_split_drop_en_split, 10110 (void *)&cmd_vf_split_drop_en_drop, 10111 (void *)&cmd_vf_split_drop_en_port_id, 10112 (void *)&cmd_vf_split_drop_en_vf_id, 10113 (void *)&cmd_vf_split_drop_en_on_off, 10114 NULL, 10115 }, 10116 }; 10117 10118 /* vf mac address configuration */ 10119 10120 /* Common result structure for vf mac address */ 10121 struct cmd_set_vf_mac_addr_result { 10122 cmdline_fixed_string_t set; 10123 cmdline_fixed_string_t vf; 10124 cmdline_fixed_string_t mac; 10125 cmdline_fixed_string_t addr; 10126 portid_t port_id; 10127 uint16_t vf_id; 10128 struct rte_ether_addr mac_addr; 10129 10130 }; 10131 10132 /* Common CLI fields for vf split drop enable disable */ 10133 static cmdline_parse_token_string_t cmd_set_vf_mac_addr_set = 10134 TOKEN_STRING_INITIALIZER 10135 (struct cmd_set_vf_mac_addr_result, 10136 set, "set"); 10137 static cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf = 10138 TOKEN_STRING_INITIALIZER 10139 (struct cmd_set_vf_mac_addr_result, 10140 vf, "vf"); 10141 static cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac = 10142 TOKEN_STRING_INITIALIZER 10143 (struct cmd_set_vf_mac_addr_result, 10144 mac, "mac"); 10145 static cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr = 10146 TOKEN_STRING_INITIALIZER 10147 (struct cmd_set_vf_mac_addr_result, 10148 addr, "addr"); 10149 static cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id = 10150 TOKEN_NUM_INITIALIZER 10151 (struct cmd_set_vf_mac_addr_result, 10152 port_id, RTE_UINT16); 10153 static cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id = 10154 TOKEN_NUM_INITIALIZER 10155 (struct cmd_set_vf_mac_addr_result, 10156 vf_id, RTE_UINT16); 10157 static cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr = 10158 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result, 10159 mac_addr); 10160 10161 static void 10162 cmd_set_vf_mac_addr_parsed( 10163 void *parsed_result, 10164 __rte_unused struct cmdline *cl, 10165 __rte_unused void *data) 10166 { 10167 struct cmd_set_vf_mac_addr_result *res = parsed_result; 10168 int ret = -ENOTSUP; 10169 10170 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 10171 return; 10172 10173 #ifdef RTE_NET_IXGBE 10174 if (ret == -ENOTSUP) 10175 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id, 10176 &res->mac_addr); 10177 #endif 10178 #ifdef RTE_NET_I40E 10179 if (ret == -ENOTSUP) 10180 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id, 10181 &res->mac_addr); 10182 #endif 10183 #ifdef RTE_NET_BNXT 10184 if (ret == -ENOTSUP) 10185 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id, 10186 &res->mac_addr); 10187 #endif 10188 10189 switch (ret) { 10190 case 0: 10191 break; 10192 case -EINVAL: 10193 fprintf(stderr, "invalid vf_id %d or mac_addr\n", res->vf_id); 10194 break; 10195 case -ENODEV: 10196 fprintf(stderr, "invalid port_id %d\n", res->port_id); 10197 break; 10198 case -ENOTSUP: 10199 fprintf(stderr, "function not implemented\n"); 10200 break; 10201 default: 10202 fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); 10203 } 10204 } 10205 10206 static cmdline_parse_inst_t cmd_set_vf_mac_addr = { 10207 .f = cmd_set_vf_mac_addr_parsed, 10208 .data = NULL, 10209 .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>", 10210 .tokens = { 10211 (void *)&cmd_set_vf_mac_addr_set, 10212 (void *)&cmd_set_vf_mac_addr_vf, 10213 (void *)&cmd_set_vf_mac_addr_mac, 10214 (void *)&cmd_set_vf_mac_addr_addr, 10215 (void *)&cmd_set_vf_mac_addr_port_id, 10216 (void *)&cmd_set_vf_mac_addr_vf_id, 10217 (void *)&cmd_set_vf_mac_addr_mac_addr, 10218 NULL, 10219 }, 10220 }; 10221 10222 /* MACsec configuration */ 10223 10224 /* Common result structure for MACsec offload enable */ 10225 struct cmd_macsec_offload_on_result { 10226 cmdline_fixed_string_t set; 10227 cmdline_fixed_string_t macsec; 10228 cmdline_fixed_string_t offload; 10229 portid_t port_id; 10230 cmdline_fixed_string_t on; 10231 cmdline_fixed_string_t encrypt; 10232 cmdline_fixed_string_t en_on_off; 10233 cmdline_fixed_string_t replay_protect; 10234 cmdline_fixed_string_t rp_on_off; 10235 }; 10236 10237 /* Common CLI fields for MACsec offload disable */ 10238 static cmdline_parse_token_string_t cmd_macsec_offload_on_set = 10239 TOKEN_STRING_INITIALIZER 10240 (struct cmd_macsec_offload_on_result, 10241 set, "set"); 10242 static cmdline_parse_token_string_t cmd_macsec_offload_on_macsec = 10243 TOKEN_STRING_INITIALIZER 10244 (struct cmd_macsec_offload_on_result, 10245 macsec, "macsec"); 10246 static cmdline_parse_token_string_t cmd_macsec_offload_on_offload = 10247 TOKEN_STRING_INITIALIZER 10248 (struct cmd_macsec_offload_on_result, 10249 offload, "offload"); 10250 static cmdline_parse_token_num_t cmd_macsec_offload_on_port_id = 10251 TOKEN_NUM_INITIALIZER 10252 (struct cmd_macsec_offload_on_result, 10253 port_id, RTE_UINT16); 10254 static cmdline_parse_token_string_t cmd_macsec_offload_on_on = 10255 TOKEN_STRING_INITIALIZER 10256 (struct cmd_macsec_offload_on_result, 10257 on, "on"); 10258 static cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt = 10259 TOKEN_STRING_INITIALIZER 10260 (struct cmd_macsec_offload_on_result, 10261 encrypt, "encrypt"); 10262 static cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off = 10263 TOKEN_STRING_INITIALIZER 10264 (struct cmd_macsec_offload_on_result, 10265 en_on_off, "on#off"); 10266 static cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect = 10267 TOKEN_STRING_INITIALIZER 10268 (struct cmd_macsec_offload_on_result, 10269 replay_protect, "replay-protect"); 10270 static cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off = 10271 TOKEN_STRING_INITIALIZER 10272 (struct cmd_macsec_offload_on_result, 10273 rp_on_off, "on#off"); 10274 10275 static void 10276 cmd_set_macsec_offload_on_parsed( 10277 void *parsed_result, 10278 __rte_unused struct cmdline *cl, 10279 __rte_unused void *data) 10280 { 10281 struct cmd_macsec_offload_on_result *res = parsed_result; 10282 int ret = -ENOTSUP; 10283 portid_t port_id = res->port_id; 10284 int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0; 10285 int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0; 10286 struct rte_eth_dev_info dev_info; 10287 10288 if (port_id_is_invalid(port_id, ENABLED_WARN)) 10289 return; 10290 if (!port_is_stopped(port_id)) { 10291 fprintf(stderr, "Please stop port %d first\n", port_id); 10292 return; 10293 } 10294 10295 ret = eth_dev_info_get_print_err(port_id, &dev_info); 10296 if (ret != 0) 10297 return; 10298 10299 if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) { 10300 #ifdef RTE_NET_IXGBE 10301 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp); 10302 #endif 10303 } 10304 RTE_SET_USED(en); 10305 RTE_SET_USED(rp); 10306 10307 switch (ret) { 10308 case 0: 10309 ports[port_id].dev_conf.txmode.offloads |= 10310 RTE_ETH_TX_OFFLOAD_MACSEC_INSERT; 10311 cmd_reconfig_device_queue(port_id, 1, 1); 10312 break; 10313 case -ENODEV: 10314 fprintf(stderr, "invalid port_id %d\n", port_id); 10315 break; 10316 case -ENOTSUP: 10317 fprintf(stderr, "not supported on port %d\n", port_id); 10318 break; 10319 default: 10320 fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); 10321 } 10322 } 10323 10324 static cmdline_parse_inst_t cmd_set_macsec_offload_on = { 10325 .f = cmd_set_macsec_offload_on_parsed, 10326 .data = NULL, 10327 .help_str = "set macsec offload <port_id> on " 10328 "encrypt on|off replay-protect on|off", 10329 .tokens = { 10330 (void *)&cmd_macsec_offload_on_set, 10331 (void *)&cmd_macsec_offload_on_macsec, 10332 (void *)&cmd_macsec_offload_on_offload, 10333 (void *)&cmd_macsec_offload_on_port_id, 10334 (void *)&cmd_macsec_offload_on_on, 10335 (void *)&cmd_macsec_offload_on_encrypt, 10336 (void *)&cmd_macsec_offload_on_en_on_off, 10337 (void *)&cmd_macsec_offload_on_replay_protect, 10338 (void *)&cmd_macsec_offload_on_rp_on_off, 10339 NULL, 10340 }, 10341 }; 10342 10343 /* Common result structure for MACsec offload disable */ 10344 struct cmd_macsec_offload_off_result { 10345 cmdline_fixed_string_t set; 10346 cmdline_fixed_string_t macsec; 10347 cmdline_fixed_string_t offload; 10348 portid_t port_id; 10349 cmdline_fixed_string_t off; 10350 }; 10351 10352 /* Common CLI fields for MACsec offload disable */ 10353 static cmdline_parse_token_string_t cmd_macsec_offload_off_set = 10354 TOKEN_STRING_INITIALIZER 10355 (struct cmd_macsec_offload_off_result, 10356 set, "set"); 10357 static cmdline_parse_token_string_t cmd_macsec_offload_off_macsec = 10358 TOKEN_STRING_INITIALIZER 10359 (struct cmd_macsec_offload_off_result, 10360 macsec, "macsec"); 10361 static cmdline_parse_token_string_t cmd_macsec_offload_off_offload = 10362 TOKEN_STRING_INITIALIZER 10363 (struct cmd_macsec_offload_off_result, 10364 offload, "offload"); 10365 static cmdline_parse_token_num_t cmd_macsec_offload_off_port_id = 10366 TOKEN_NUM_INITIALIZER 10367 (struct cmd_macsec_offload_off_result, 10368 port_id, RTE_UINT16); 10369 static cmdline_parse_token_string_t cmd_macsec_offload_off_off = 10370 TOKEN_STRING_INITIALIZER 10371 (struct cmd_macsec_offload_off_result, 10372 off, "off"); 10373 10374 static void 10375 cmd_set_macsec_offload_off_parsed( 10376 void *parsed_result, 10377 __rte_unused struct cmdline *cl, 10378 __rte_unused void *data) 10379 { 10380 struct cmd_macsec_offload_off_result *res = parsed_result; 10381 int ret = -ENOTSUP; 10382 struct rte_eth_dev_info dev_info; 10383 portid_t port_id = res->port_id; 10384 10385 if (port_id_is_invalid(port_id, ENABLED_WARN)) 10386 return; 10387 if (!port_is_stopped(port_id)) { 10388 fprintf(stderr, "Please stop port %d first\n", port_id); 10389 return; 10390 } 10391 10392 ret = eth_dev_info_get_print_err(port_id, &dev_info); 10393 if (ret != 0) 10394 return; 10395 10396 if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) { 10397 #ifdef RTE_NET_IXGBE 10398 ret = rte_pmd_ixgbe_macsec_disable(port_id); 10399 #endif 10400 } 10401 switch (ret) { 10402 case 0: 10403 ports[port_id].dev_conf.txmode.offloads &= 10404 ~RTE_ETH_TX_OFFLOAD_MACSEC_INSERT; 10405 cmd_reconfig_device_queue(port_id, 1, 1); 10406 break; 10407 case -ENODEV: 10408 fprintf(stderr, "invalid port_id %d\n", port_id); 10409 break; 10410 case -ENOTSUP: 10411 fprintf(stderr, "not supported on port %d\n", port_id); 10412 break; 10413 default: 10414 fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); 10415 } 10416 } 10417 10418 static cmdline_parse_inst_t cmd_set_macsec_offload_off = { 10419 .f = cmd_set_macsec_offload_off_parsed, 10420 .data = NULL, 10421 .help_str = "set macsec offload <port_id> off", 10422 .tokens = { 10423 (void *)&cmd_macsec_offload_off_set, 10424 (void *)&cmd_macsec_offload_off_macsec, 10425 (void *)&cmd_macsec_offload_off_offload, 10426 (void *)&cmd_macsec_offload_off_port_id, 10427 (void *)&cmd_macsec_offload_off_off, 10428 NULL, 10429 }, 10430 }; 10431 10432 /* Common result structure for MACsec secure connection configure */ 10433 struct cmd_macsec_sc_result { 10434 cmdline_fixed_string_t set; 10435 cmdline_fixed_string_t macsec; 10436 cmdline_fixed_string_t sc; 10437 cmdline_fixed_string_t tx_rx; 10438 portid_t port_id; 10439 struct rte_ether_addr mac; 10440 uint16_t pi; 10441 }; 10442 10443 /* Common CLI fields for MACsec secure connection configure */ 10444 static cmdline_parse_token_string_t cmd_macsec_sc_set = 10445 TOKEN_STRING_INITIALIZER 10446 (struct cmd_macsec_sc_result, 10447 set, "set"); 10448 static cmdline_parse_token_string_t cmd_macsec_sc_macsec = 10449 TOKEN_STRING_INITIALIZER 10450 (struct cmd_macsec_sc_result, 10451 macsec, "macsec"); 10452 static cmdline_parse_token_string_t cmd_macsec_sc_sc = 10453 TOKEN_STRING_INITIALIZER 10454 (struct cmd_macsec_sc_result, 10455 sc, "sc"); 10456 static cmdline_parse_token_string_t cmd_macsec_sc_tx_rx = 10457 TOKEN_STRING_INITIALIZER 10458 (struct cmd_macsec_sc_result, 10459 tx_rx, "tx#rx"); 10460 static cmdline_parse_token_num_t cmd_macsec_sc_port_id = 10461 TOKEN_NUM_INITIALIZER 10462 (struct cmd_macsec_sc_result, 10463 port_id, RTE_UINT16); 10464 static cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac = 10465 TOKEN_ETHERADDR_INITIALIZER 10466 (struct cmd_macsec_sc_result, 10467 mac); 10468 static cmdline_parse_token_num_t cmd_macsec_sc_pi = 10469 TOKEN_NUM_INITIALIZER 10470 (struct cmd_macsec_sc_result, 10471 pi, RTE_UINT16); 10472 10473 static void 10474 cmd_set_macsec_sc_parsed( 10475 void *parsed_result, 10476 __rte_unused struct cmdline *cl, 10477 __rte_unused void *data) 10478 { 10479 struct cmd_macsec_sc_result *res = parsed_result; 10480 int ret = -ENOTSUP; 10481 int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0; 10482 10483 #ifdef RTE_NET_IXGBE 10484 ret = is_tx ? 10485 rte_pmd_ixgbe_macsec_config_txsc(res->port_id, 10486 res->mac.addr_bytes) : 10487 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id, 10488 res->mac.addr_bytes, res->pi); 10489 #endif 10490 RTE_SET_USED(is_tx); 10491 10492 switch (ret) { 10493 case 0: 10494 break; 10495 case -ENODEV: 10496 fprintf(stderr, "invalid port_id %d\n", res->port_id); 10497 break; 10498 case -ENOTSUP: 10499 fprintf(stderr, "not supported on port %d\n", res->port_id); 10500 break; 10501 default: 10502 fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); 10503 } 10504 } 10505 10506 static cmdline_parse_inst_t cmd_set_macsec_sc = { 10507 .f = cmd_set_macsec_sc_parsed, 10508 .data = NULL, 10509 .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>", 10510 .tokens = { 10511 (void *)&cmd_macsec_sc_set, 10512 (void *)&cmd_macsec_sc_macsec, 10513 (void *)&cmd_macsec_sc_sc, 10514 (void *)&cmd_macsec_sc_tx_rx, 10515 (void *)&cmd_macsec_sc_port_id, 10516 (void *)&cmd_macsec_sc_mac, 10517 (void *)&cmd_macsec_sc_pi, 10518 NULL, 10519 }, 10520 }; 10521 10522 /* Common result structure for MACsec secure connection configure */ 10523 struct cmd_macsec_sa_result { 10524 cmdline_fixed_string_t set; 10525 cmdline_fixed_string_t macsec; 10526 cmdline_fixed_string_t sa; 10527 cmdline_fixed_string_t tx_rx; 10528 portid_t port_id; 10529 uint8_t idx; 10530 uint8_t an; 10531 uint32_t pn; 10532 cmdline_fixed_string_t key; 10533 }; 10534 10535 /* Common CLI fields for MACsec secure connection configure */ 10536 static cmdline_parse_token_string_t cmd_macsec_sa_set = 10537 TOKEN_STRING_INITIALIZER 10538 (struct cmd_macsec_sa_result, 10539 set, "set"); 10540 static cmdline_parse_token_string_t cmd_macsec_sa_macsec = 10541 TOKEN_STRING_INITIALIZER 10542 (struct cmd_macsec_sa_result, 10543 macsec, "macsec"); 10544 static cmdline_parse_token_string_t cmd_macsec_sa_sa = 10545 TOKEN_STRING_INITIALIZER 10546 (struct cmd_macsec_sa_result, 10547 sa, "sa"); 10548 static cmdline_parse_token_string_t cmd_macsec_sa_tx_rx = 10549 TOKEN_STRING_INITIALIZER 10550 (struct cmd_macsec_sa_result, 10551 tx_rx, "tx#rx"); 10552 static cmdline_parse_token_num_t cmd_macsec_sa_port_id = 10553 TOKEN_NUM_INITIALIZER 10554 (struct cmd_macsec_sa_result, 10555 port_id, RTE_UINT16); 10556 static cmdline_parse_token_num_t cmd_macsec_sa_idx = 10557 TOKEN_NUM_INITIALIZER 10558 (struct cmd_macsec_sa_result, 10559 idx, RTE_UINT8); 10560 static cmdline_parse_token_num_t cmd_macsec_sa_an = 10561 TOKEN_NUM_INITIALIZER 10562 (struct cmd_macsec_sa_result, 10563 an, RTE_UINT8); 10564 static cmdline_parse_token_num_t cmd_macsec_sa_pn = 10565 TOKEN_NUM_INITIALIZER 10566 (struct cmd_macsec_sa_result, 10567 pn, RTE_UINT32); 10568 static cmdline_parse_token_string_t cmd_macsec_sa_key = 10569 TOKEN_STRING_INITIALIZER 10570 (struct cmd_macsec_sa_result, 10571 key, NULL); 10572 10573 static void 10574 cmd_set_macsec_sa_parsed( 10575 void *parsed_result, 10576 __rte_unused struct cmdline *cl, 10577 __rte_unused void *data) 10578 { 10579 struct cmd_macsec_sa_result *res = parsed_result; 10580 int ret = -ENOTSUP; 10581 int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0; 10582 uint8_t key[16] = { 0 }; 10583 uint8_t xdgt0; 10584 uint8_t xdgt1; 10585 int key_len; 10586 int i; 10587 10588 key_len = strlen(res->key) / 2; 10589 if (key_len > 16) 10590 key_len = 16; 10591 10592 for (i = 0; i < key_len; i++) { 10593 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2)); 10594 if (xdgt0 == 0xFF) 10595 return; 10596 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1); 10597 if (xdgt1 == 0xFF) 10598 return; 10599 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1); 10600 } 10601 10602 #ifdef RTE_NET_IXGBE 10603 ret = is_tx ? 10604 rte_pmd_ixgbe_macsec_select_txsa(res->port_id, 10605 res->idx, res->an, res->pn, key) : 10606 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id, 10607 res->idx, res->an, res->pn, key); 10608 #endif 10609 RTE_SET_USED(is_tx); 10610 RTE_SET_USED(key); 10611 10612 switch (ret) { 10613 case 0: 10614 break; 10615 case -EINVAL: 10616 fprintf(stderr, "invalid idx %d or an %d\n", res->idx, res->an); 10617 break; 10618 case -ENODEV: 10619 fprintf(stderr, "invalid port_id %d\n", res->port_id); 10620 break; 10621 case -ENOTSUP: 10622 fprintf(stderr, "not supported on port %d\n", res->port_id); 10623 break; 10624 default: 10625 fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); 10626 } 10627 } 10628 10629 static cmdline_parse_inst_t cmd_set_macsec_sa = { 10630 .f = cmd_set_macsec_sa_parsed, 10631 .data = NULL, 10632 .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>", 10633 .tokens = { 10634 (void *)&cmd_macsec_sa_set, 10635 (void *)&cmd_macsec_sa_macsec, 10636 (void *)&cmd_macsec_sa_sa, 10637 (void *)&cmd_macsec_sa_tx_rx, 10638 (void *)&cmd_macsec_sa_port_id, 10639 (void *)&cmd_macsec_sa_idx, 10640 (void *)&cmd_macsec_sa_an, 10641 (void *)&cmd_macsec_sa_pn, 10642 (void *)&cmd_macsec_sa_key, 10643 NULL, 10644 }, 10645 }; 10646 10647 /* Common definition of VF and TC TX bandwidth configuration */ 10648 struct cmd_vf_tc_bw_result { 10649 cmdline_fixed_string_t set; 10650 cmdline_fixed_string_t tc; 10651 cmdline_fixed_string_t tx; 10652 cmdline_fixed_string_t min_bw; 10653 portid_t port_id; 10654 cmdline_fixed_string_t bw_list; 10655 }; 10656 10657 static cmdline_parse_token_string_t cmd_vf_tc_bw_set = 10658 TOKEN_STRING_INITIALIZER 10659 (struct cmd_vf_tc_bw_result, 10660 set, "set"); 10661 static cmdline_parse_token_string_t cmd_vf_tc_bw_tc = 10662 TOKEN_STRING_INITIALIZER 10663 (struct cmd_vf_tc_bw_result, 10664 tc, "tc"); 10665 static cmdline_parse_token_string_t cmd_vf_tc_bw_tx = 10666 TOKEN_STRING_INITIALIZER 10667 (struct cmd_vf_tc_bw_result, 10668 tx, "tx"); 10669 static cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw = 10670 TOKEN_STRING_INITIALIZER 10671 (struct cmd_vf_tc_bw_result, 10672 min_bw, "min-bandwidth"); 10673 static cmdline_parse_token_num_t cmd_vf_tc_bw_port_id = 10674 TOKEN_NUM_INITIALIZER 10675 (struct cmd_vf_tc_bw_result, 10676 port_id, RTE_UINT16); 10677 static cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list = 10678 TOKEN_STRING_INITIALIZER 10679 (struct cmd_vf_tc_bw_result, 10680 bw_list, NULL); 10681 10682 static int 10683 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list, 10684 uint8_t *tc_num, 10685 char *str) 10686 { 10687 uint32_t size; 10688 const char *p, *p0 = str; 10689 char s[256]; 10690 char *end; 10691 char *str_fld[16]; 10692 uint16_t i; 10693 int ret; 10694 10695 p = strchr(p0, '('); 10696 if (p == NULL) { 10697 fprintf(stderr, 10698 "The bandwidth-list should be '(bw1, bw2, ...)'\n"); 10699 return -1; 10700 } 10701 p++; 10702 p0 = strchr(p, ')'); 10703 if (p0 == NULL) { 10704 fprintf(stderr, 10705 "The bandwidth-list should be '(bw1, bw2, ...)'\n"); 10706 return -1; 10707 } 10708 size = p0 - p; 10709 if (size >= sizeof(s)) { 10710 fprintf(stderr, 10711 "The string size exceeds the internal buffer size\n"); 10712 return -1; 10713 } 10714 snprintf(s, sizeof(s), "%.*s", size, p); 10715 ret = rte_strsplit(s, sizeof(s), str_fld, 16, ','); 10716 if (ret <= 0) { 10717 fprintf(stderr, "Failed to get the bandwidth list.\n"); 10718 return -1; 10719 } 10720 *tc_num = ret; 10721 for (i = 0; i < ret; i++) 10722 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0); 10723 10724 return 0; 10725 } 10726 10727 static void 10728 cmd_tc_min_bw_parsed( 10729 void *parsed_result, 10730 __rte_unused struct cmdline *cl, 10731 __rte_unused void *data) 10732 { 10733 struct cmd_vf_tc_bw_result *res = parsed_result; 10734 struct rte_port *port; 10735 uint8_t tc_num; 10736 uint8_t bw[16]; 10737 int ret = -ENOTSUP; 10738 10739 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 10740 return; 10741 10742 port = &ports[res->port_id]; 10743 /** Check if the port is not started **/ 10744 if (port->port_status != RTE_PORT_STOPPED) { 10745 fprintf(stderr, "Please stop port %d first\n", res->port_id); 10746 return; 10747 } 10748 10749 ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list); 10750 if (ret) 10751 return; 10752 10753 #ifdef RTE_NET_IXGBE 10754 ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw); 10755 #endif 10756 10757 switch (ret) { 10758 case 0: 10759 break; 10760 case -EINVAL: 10761 fprintf(stderr, "invalid bandwidth\n"); 10762 break; 10763 case -ENODEV: 10764 fprintf(stderr, "invalid port_id %d\n", res->port_id); 10765 break; 10766 case -ENOTSUP: 10767 fprintf(stderr, "function not implemented\n"); 10768 break; 10769 default: 10770 fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); 10771 } 10772 } 10773 10774 static cmdline_parse_inst_t cmd_tc_min_bw = { 10775 .f = cmd_tc_min_bw_parsed, 10776 .data = NULL, 10777 .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>", 10778 .tokens = { 10779 (void *)&cmd_vf_tc_bw_set, 10780 (void *)&cmd_vf_tc_bw_tc, 10781 (void *)&cmd_vf_tc_bw_tx, 10782 (void *)&cmd_vf_tc_bw_min_bw, 10783 (void *)&cmd_vf_tc_bw_port_id, 10784 (void *)&cmd_vf_tc_bw_bw_list, 10785 NULL, 10786 }, 10787 }; 10788 10789 /** Set VXLAN encapsulation details */ 10790 struct cmd_set_vxlan_result { 10791 cmdline_fixed_string_t set; 10792 cmdline_fixed_string_t vxlan; 10793 cmdline_fixed_string_t pos_token; 10794 cmdline_fixed_string_t ip_version; 10795 uint32_t vlan_present:1; 10796 uint32_t vni; 10797 uint16_t udp_src; 10798 uint16_t udp_dst; 10799 cmdline_ipaddr_t ip_src; 10800 cmdline_ipaddr_t ip_dst; 10801 uint16_t tci; 10802 uint8_t tos; 10803 uint8_t ttl; 10804 struct rte_ether_addr eth_src; 10805 struct rte_ether_addr eth_dst; 10806 }; 10807 10808 static cmdline_parse_token_string_t cmd_set_vxlan_set = 10809 TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set"); 10810 static cmdline_parse_token_string_t cmd_set_vxlan_vxlan = 10811 TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan"); 10812 static cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl = 10813 TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, 10814 "vxlan-tos-ttl"); 10815 static cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan = 10816 TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, 10817 "vxlan-with-vlan"); 10818 static cmdline_parse_token_string_t cmd_set_vxlan_ip_version = 10819 TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token, 10820 "ip-version"); 10821 static cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value = 10822 TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version, 10823 "ipv4#ipv6"); 10824 static cmdline_parse_token_string_t cmd_set_vxlan_vni = 10825 TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token, 10826 "vni"); 10827 static cmdline_parse_token_num_t cmd_set_vxlan_vni_value = 10828 TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, RTE_UINT32); 10829 static cmdline_parse_token_string_t cmd_set_vxlan_udp_src = 10830 TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token, 10831 "udp-src"); 10832 static cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value = 10833 TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, RTE_UINT16); 10834 static cmdline_parse_token_string_t cmd_set_vxlan_udp_dst = 10835 TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token, 10836 "udp-dst"); 10837 static cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value = 10838 TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, RTE_UINT16); 10839 static cmdline_parse_token_string_t cmd_set_vxlan_ip_tos = 10840 TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token, 10841 "ip-tos"); 10842 static cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value = 10843 TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, RTE_UINT8); 10844 static cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl = 10845 TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token, 10846 "ip-ttl"); 10847 static cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value = 10848 TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, RTE_UINT8); 10849 static cmdline_parse_token_string_t cmd_set_vxlan_ip_src = 10850 TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token, 10851 "ip-src"); 10852 static cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value = 10853 TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src); 10854 static cmdline_parse_token_string_t cmd_set_vxlan_ip_dst = 10855 TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token, 10856 "ip-dst"); 10857 static cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value = 10858 TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst); 10859 static cmdline_parse_token_string_t cmd_set_vxlan_vlan = 10860 TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token, 10861 "vlan-tci"); 10862 static cmdline_parse_token_num_t cmd_set_vxlan_vlan_value = 10863 TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, RTE_UINT16); 10864 static cmdline_parse_token_string_t cmd_set_vxlan_eth_src = 10865 TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token, 10866 "eth-src"); 10867 static cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value = 10868 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src); 10869 static cmdline_parse_token_string_t cmd_set_vxlan_eth_dst = 10870 TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token, 10871 "eth-dst"); 10872 static cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value = 10873 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst); 10874 10875 static void cmd_set_vxlan_parsed(void *parsed_result, 10876 __rte_unused struct cmdline *cl, 10877 __rte_unused void *data) 10878 { 10879 struct cmd_set_vxlan_result *res = parsed_result; 10880 union { 10881 uint32_t vxlan_id; 10882 uint8_t vni[4]; 10883 } id = { 10884 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff), 10885 }; 10886 10887 vxlan_encap_conf.select_tos_ttl = 0; 10888 if (strcmp(res->vxlan, "vxlan") == 0) 10889 vxlan_encap_conf.select_vlan = 0; 10890 else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0) 10891 vxlan_encap_conf.select_vlan = 1; 10892 else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) { 10893 vxlan_encap_conf.select_vlan = 0; 10894 vxlan_encap_conf.select_tos_ttl = 1; 10895 } 10896 if (strcmp(res->ip_version, "ipv4") == 0) 10897 vxlan_encap_conf.select_ipv4 = 1; 10898 else if (strcmp(res->ip_version, "ipv6") == 0) 10899 vxlan_encap_conf.select_ipv4 = 0; 10900 else 10901 return; 10902 rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3); 10903 vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src); 10904 vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst); 10905 vxlan_encap_conf.ip_tos = res->tos; 10906 vxlan_encap_conf.ip_ttl = res->ttl; 10907 if (vxlan_encap_conf.select_ipv4) { 10908 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src); 10909 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst); 10910 } else { 10911 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src); 10912 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst); 10913 } 10914 if (vxlan_encap_conf.select_vlan) 10915 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci); 10916 rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes, 10917 RTE_ETHER_ADDR_LEN); 10918 rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes, 10919 RTE_ETHER_ADDR_LEN); 10920 } 10921 10922 static cmdline_parse_inst_t cmd_set_vxlan = { 10923 .f = cmd_set_vxlan_parsed, 10924 .data = NULL, 10925 .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src" 10926 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>" 10927 " eth-src <eth-src> eth-dst <eth-dst>", 10928 .tokens = { 10929 (void *)&cmd_set_vxlan_set, 10930 (void *)&cmd_set_vxlan_vxlan, 10931 (void *)&cmd_set_vxlan_ip_version, 10932 (void *)&cmd_set_vxlan_ip_version_value, 10933 (void *)&cmd_set_vxlan_vni, 10934 (void *)&cmd_set_vxlan_vni_value, 10935 (void *)&cmd_set_vxlan_udp_src, 10936 (void *)&cmd_set_vxlan_udp_src_value, 10937 (void *)&cmd_set_vxlan_udp_dst, 10938 (void *)&cmd_set_vxlan_udp_dst_value, 10939 (void *)&cmd_set_vxlan_ip_src, 10940 (void *)&cmd_set_vxlan_ip_src_value, 10941 (void *)&cmd_set_vxlan_ip_dst, 10942 (void *)&cmd_set_vxlan_ip_dst_value, 10943 (void *)&cmd_set_vxlan_eth_src, 10944 (void *)&cmd_set_vxlan_eth_src_value, 10945 (void *)&cmd_set_vxlan_eth_dst, 10946 (void *)&cmd_set_vxlan_eth_dst_value, 10947 NULL, 10948 }, 10949 }; 10950 10951 static cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = { 10952 .f = cmd_set_vxlan_parsed, 10953 .data = NULL, 10954 .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src" 10955 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>" 10956 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>" 10957 " eth-dst <eth-dst>", 10958 .tokens = { 10959 (void *)&cmd_set_vxlan_set, 10960 (void *)&cmd_set_vxlan_vxlan_tos_ttl, 10961 (void *)&cmd_set_vxlan_ip_version, 10962 (void *)&cmd_set_vxlan_ip_version_value, 10963 (void *)&cmd_set_vxlan_vni, 10964 (void *)&cmd_set_vxlan_vni_value, 10965 (void *)&cmd_set_vxlan_udp_src, 10966 (void *)&cmd_set_vxlan_udp_src_value, 10967 (void *)&cmd_set_vxlan_udp_dst, 10968 (void *)&cmd_set_vxlan_udp_dst_value, 10969 (void *)&cmd_set_vxlan_ip_tos, 10970 (void *)&cmd_set_vxlan_ip_tos_value, 10971 (void *)&cmd_set_vxlan_ip_ttl, 10972 (void *)&cmd_set_vxlan_ip_ttl_value, 10973 (void *)&cmd_set_vxlan_ip_src, 10974 (void *)&cmd_set_vxlan_ip_src_value, 10975 (void *)&cmd_set_vxlan_ip_dst, 10976 (void *)&cmd_set_vxlan_ip_dst_value, 10977 (void *)&cmd_set_vxlan_eth_src, 10978 (void *)&cmd_set_vxlan_eth_src_value, 10979 (void *)&cmd_set_vxlan_eth_dst, 10980 (void *)&cmd_set_vxlan_eth_dst_value, 10981 NULL, 10982 }, 10983 }; 10984 10985 static cmdline_parse_inst_t cmd_set_vxlan_with_vlan = { 10986 .f = cmd_set_vxlan_parsed, 10987 .data = NULL, 10988 .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>" 10989 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst" 10990 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst" 10991 " <eth-dst>", 10992 .tokens = { 10993 (void *)&cmd_set_vxlan_set, 10994 (void *)&cmd_set_vxlan_vxlan_with_vlan, 10995 (void *)&cmd_set_vxlan_ip_version, 10996 (void *)&cmd_set_vxlan_ip_version_value, 10997 (void *)&cmd_set_vxlan_vni, 10998 (void *)&cmd_set_vxlan_vni_value, 10999 (void *)&cmd_set_vxlan_udp_src, 11000 (void *)&cmd_set_vxlan_udp_src_value, 11001 (void *)&cmd_set_vxlan_udp_dst, 11002 (void *)&cmd_set_vxlan_udp_dst_value, 11003 (void *)&cmd_set_vxlan_ip_src, 11004 (void *)&cmd_set_vxlan_ip_src_value, 11005 (void *)&cmd_set_vxlan_ip_dst, 11006 (void *)&cmd_set_vxlan_ip_dst_value, 11007 (void *)&cmd_set_vxlan_vlan, 11008 (void *)&cmd_set_vxlan_vlan_value, 11009 (void *)&cmd_set_vxlan_eth_src, 11010 (void *)&cmd_set_vxlan_eth_src_value, 11011 (void *)&cmd_set_vxlan_eth_dst, 11012 (void *)&cmd_set_vxlan_eth_dst_value, 11013 NULL, 11014 }, 11015 }; 11016 11017 /** Set NVGRE encapsulation details */ 11018 struct cmd_set_nvgre_result { 11019 cmdline_fixed_string_t set; 11020 cmdline_fixed_string_t nvgre; 11021 cmdline_fixed_string_t pos_token; 11022 cmdline_fixed_string_t ip_version; 11023 uint32_t tni; 11024 cmdline_ipaddr_t ip_src; 11025 cmdline_ipaddr_t ip_dst; 11026 uint16_t tci; 11027 struct rte_ether_addr eth_src; 11028 struct rte_ether_addr eth_dst; 11029 }; 11030 11031 static cmdline_parse_token_string_t cmd_set_nvgre_set = 11032 TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set"); 11033 static cmdline_parse_token_string_t cmd_set_nvgre_nvgre = 11034 TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre"); 11035 static cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan = 11036 TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, 11037 "nvgre-with-vlan"); 11038 static cmdline_parse_token_string_t cmd_set_nvgre_ip_version = 11039 TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token, 11040 "ip-version"); 11041 static cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value = 11042 TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version, 11043 "ipv4#ipv6"); 11044 static cmdline_parse_token_string_t cmd_set_nvgre_tni = 11045 TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token, 11046 "tni"); 11047 static cmdline_parse_token_num_t cmd_set_nvgre_tni_value = 11048 TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, RTE_UINT32); 11049 static cmdline_parse_token_string_t cmd_set_nvgre_ip_src = 11050 TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token, 11051 "ip-src"); 11052 static cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value = 11053 TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src); 11054 static cmdline_parse_token_string_t cmd_set_nvgre_ip_dst = 11055 TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token, 11056 "ip-dst"); 11057 static cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value = 11058 TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst); 11059 static cmdline_parse_token_string_t cmd_set_nvgre_vlan = 11060 TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token, 11061 "vlan-tci"); 11062 static cmdline_parse_token_num_t cmd_set_nvgre_vlan_value = 11063 TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, RTE_UINT16); 11064 static cmdline_parse_token_string_t cmd_set_nvgre_eth_src = 11065 TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token, 11066 "eth-src"); 11067 static cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value = 11068 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src); 11069 static cmdline_parse_token_string_t cmd_set_nvgre_eth_dst = 11070 TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token, 11071 "eth-dst"); 11072 static cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value = 11073 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst); 11074 11075 static void cmd_set_nvgre_parsed(void *parsed_result, 11076 __rte_unused struct cmdline *cl, 11077 __rte_unused void *data) 11078 { 11079 struct cmd_set_nvgre_result *res = parsed_result; 11080 union { 11081 uint32_t nvgre_tni; 11082 uint8_t tni[4]; 11083 } id = { 11084 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff), 11085 }; 11086 11087 if (strcmp(res->nvgre, "nvgre") == 0) 11088 nvgre_encap_conf.select_vlan = 0; 11089 else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0) 11090 nvgre_encap_conf.select_vlan = 1; 11091 if (strcmp(res->ip_version, "ipv4") == 0) 11092 nvgre_encap_conf.select_ipv4 = 1; 11093 else if (strcmp(res->ip_version, "ipv6") == 0) 11094 nvgre_encap_conf.select_ipv4 = 0; 11095 else 11096 return; 11097 rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3); 11098 if (nvgre_encap_conf.select_ipv4) { 11099 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src); 11100 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst); 11101 } else { 11102 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src); 11103 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst); 11104 } 11105 if (nvgre_encap_conf.select_vlan) 11106 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci); 11107 rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes, 11108 RTE_ETHER_ADDR_LEN); 11109 rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes, 11110 RTE_ETHER_ADDR_LEN); 11111 } 11112 11113 static cmdline_parse_inst_t cmd_set_nvgre = { 11114 .f = cmd_set_nvgre_parsed, 11115 .data = NULL, 11116 .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src" 11117 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>" 11118 " eth-dst <eth-dst>", 11119 .tokens = { 11120 (void *)&cmd_set_nvgre_set, 11121 (void *)&cmd_set_nvgre_nvgre, 11122 (void *)&cmd_set_nvgre_ip_version, 11123 (void *)&cmd_set_nvgre_ip_version_value, 11124 (void *)&cmd_set_nvgre_tni, 11125 (void *)&cmd_set_nvgre_tni_value, 11126 (void *)&cmd_set_nvgre_ip_src, 11127 (void *)&cmd_set_nvgre_ip_src_value, 11128 (void *)&cmd_set_nvgre_ip_dst, 11129 (void *)&cmd_set_nvgre_ip_dst_value, 11130 (void *)&cmd_set_nvgre_eth_src, 11131 (void *)&cmd_set_nvgre_eth_src_value, 11132 (void *)&cmd_set_nvgre_eth_dst, 11133 (void *)&cmd_set_nvgre_eth_dst_value, 11134 NULL, 11135 }, 11136 }; 11137 11138 static cmdline_parse_inst_t cmd_set_nvgre_with_vlan = { 11139 .f = cmd_set_nvgre_parsed, 11140 .data = NULL, 11141 .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>" 11142 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>" 11143 " eth-src <eth-src> eth-dst <eth-dst>", 11144 .tokens = { 11145 (void *)&cmd_set_nvgre_set, 11146 (void *)&cmd_set_nvgre_nvgre_with_vlan, 11147 (void *)&cmd_set_nvgre_ip_version, 11148 (void *)&cmd_set_nvgre_ip_version_value, 11149 (void *)&cmd_set_nvgre_tni, 11150 (void *)&cmd_set_nvgre_tni_value, 11151 (void *)&cmd_set_nvgre_ip_src, 11152 (void *)&cmd_set_nvgre_ip_src_value, 11153 (void *)&cmd_set_nvgre_ip_dst, 11154 (void *)&cmd_set_nvgre_ip_dst_value, 11155 (void *)&cmd_set_nvgre_vlan, 11156 (void *)&cmd_set_nvgre_vlan_value, 11157 (void *)&cmd_set_nvgre_eth_src, 11158 (void *)&cmd_set_nvgre_eth_src_value, 11159 (void *)&cmd_set_nvgre_eth_dst, 11160 (void *)&cmd_set_nvgre_eth_dst_value, 11161 NULL, 11162 }, 11163 }; 11164 11165 /** Set L2 encapsulation details */ 11166 struct cmd_set_l2_encap_result { 11167 cmdline_fixed_string_t set; 11168 cmdline_fixed_string_t l2_encap; 11169 cmdline_fixed_string_t pos_token; 11170 cmdline_fixed_string_t ip_version; 11171 uint32_t vlan_present:1; 11172 uint16_t tci; 11173 struct rte_ether_addr eth_src; 11174 struct rte_ether_addr eth_dst; 11175 }; 11176 11177 static cmdline_parse_token_string_t cmd_set_l2_encap_set = 11178 TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set"); 11179 static cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap = 11180 TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap"); 11181 static cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan = 11182 TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, 11183 "l2_encap-with-vlan"); 11184 static cmdline_parse_token_string_t cmd_set_l2_encap_ip_version = 11185 TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token, 11186 "ip-version"); 11187 static cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value = 11188 TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version, 11189 "ipv4#ipv6"); 11190 static cmdline_parse_token_string_t cmd_set_l2_encap_vlan = 11191 TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token, 11192 "vlan-tci"); 11193 static cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value = 11194 TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, RTE_UINT16); 11195 static cmdline_parse_token_string_t cmd_set_l2_encap_eth_src = 11196 TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token, 11197 "eth-src"); 11198 static cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value = 11199 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src); 11200 static cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst = 11201 TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token, 11202 "eth-dst"); 11203 static cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value = 11204 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst); 11205 11206 static void cmd_set_l2_encap_parsed(void *parsed_result, 11207 __rte_unused struct cmdline *cl, 11208 __rte_unused void *data) 11209 { 11210 struct cmd_set_l2_encap_result *res = parsed_result; 11211 11212 if (strcmp(res->l2_encap, "l2_encap") == 0) 11213 l2_encap_conf.select_vlan = 0; 11214 else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0) 11215 l2_encap_conf.select_vlan = 1; 11216 if (strcmp(res->ip_version, "ipv4") == 0) 11217 l2_encap_conf.select_ipv4 = 1; 11218 else if (strcmp(res->ip_version, "ipv6") == 0) 11219 l2_encap_conf.select_ipv4 = 0; 11220 else 11221 return; 11222 if (l2_encap_conf.select_vlan) 11223 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci); 11224 rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes, 11225 RTE_ETHER_ADDR_LEN); 11226 rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes, 11227 RTE_ETHER_ADDR_LEN); 11228 } 11229 11230 static cmdline_parse_inst_t cmd_set_l2_encap = { 11231 .f = cmd_set_l2_encap_parsed, 11232 .data = NULL, 11233 .help_str = "set l2_encap ip-version ipv4|ipv6" 11234 " eth-src <eth-src> eth-dst <eth-dst>", 11235 .tokens = { 11236 (void *)&cmd_set_l2_encap_set, 11237 (void *)&cmd_set_l2_encap_l2_encap, 11238 (void *)&cmd_set_l2_encap_ip_version, 11239 (void *)&cmd_set_l2_encap_ip_version_value, 11240 (void *)&cmd_set_l2_encap_eth_src, 11241 (void *)&cmd_set_l2_encap_eth_src_value, 11242 (void *)&cmd_set_l2_encap_eth_dst, 11243 (void *)&cmd_set_l2_encap_eth_dst_value, 11244 NULL, 11245 }, 11246 }; 11247 11248 static cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = { 11249 .f = cmd_set_l2_encap_parsed, 11250 .data = NULL, 11251 .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6" 11252 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>", 11253 .tokens = { 11254 (void *)&cmd_set_l2_encap_set, 11255 (void *)&cmd_set_l2_encap_l2_encap_with_vlan, 11256 (void *)&cmd_set_l2_encap_ip_version, 11257 (void *)&cmd_set_l2_encap_ip_version_value, 11258 (void *)&cmd_set_l2_encap_vlan, 11259 (void *)&cmd_set_l2_encap_vlan_value, 11260 (void *)&cmd_set_l2_encap_eth_src, 11261 (void *)&cmd_set_l2_encap_eth_src_value, 11262 (void *)&cmd_set_l2_encap_eth_dst, 11263 (void *)&cmd_set_l2_encap_eth_dst_value, 11264 NULL, 11265 }, 11266 }; 11267 11268 /** Set L2 decapsulation details */ 11269 struct cmd_set_l2_decap_result { 11270 cmdline_fixed_string_t set; 11271 cmdline_fixed_string_t l2_decap; 11272 cmdline_fixed_string_t pos_token; 11273 uint32_t vlan_present:1; 11274 }; 11275 11276 static cmdline_parse_token_string_t cmd_set_l2_decap_set = 11277 TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set"); 11278 static cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap = 11279 TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap, 11280 "l2_decap"); 11281 static cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan = 11282 TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap, 11283 "l2_decap-with-vlan"); 11284 11285 static void cmd_set_l2_decap_parsed(void *parsed_result, 11286 __rte_unused struct cmdline *cl, 11287 __rte_unused void *data) 11288 { 11289 struct cmd_set_l2_decap_result *res = parsed_result; 11290 11291 if (strcmp(res->l2_decap, "l2_decap") == 0) 11292 l2_decap_conf.select_vlan = 0; 11293 else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0) 11294 l2_decap_conf.select_vlan = 1; 11295 } 11296 11297 static cmdline_parse_inst_t cmd_set_l2_decap = { 11298 .f = cmd_set_l2_decap_parsed, 11299 .data = NULL, 11300 .help_str = "set l2_decap", 11301 .tokens = { 11302 (void *)&cmd_set_l2_decap_set, 11303 (void *)&cmd_set_l2_decap_l2_decap, 11304 NULL, 11305 }, 11306 }; 11307 11308 static cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = { 11309 .f = cmd_set_l2_decap_parsed, 11310 .data = NULL, 11311 .help_str = "set l2_decap-with-vlan", 11312 .tokens = { 11313 (void *)&cmd_set_l2_decap_set, 11314 (void *)&cmd_set_l2_decap_l2_decap_with_vlan, 11315 NULL, 11316 }, 11317 }; 11318 11319 /** Set MPLSoGRE encapsulation details */ 11320 struct cmd_set_mplsogre_encap_result { 11321 cmdline_fixed_string_t set; 11322 cmdline_fixed_string_t mplsogre; 11323 cmdline_fixed_string_t pos_token; 11324 cmdline_fixed_string_t ip_version; 11325 uint32_t vlan_present:1; 11326 uint32_t label; 11327 cmdline_ipaddr_t ip_src; 11328 cmdline_ipaddr_t ip_dst; 11329 uint16_t tci; 11330 struct rte_ether_addr eth_src; 11331 struct rte_ether_addr eth_dst; 11332 }; 11333 11334 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_set = 11335 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set, 11336 "set"); 11337 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap = 11338 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre, 11339 "mplsogre_encap"); 11340 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan = 11341 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, 11342 mplsogre, "mplsogre_encap-with-vlan"); 11343 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version = 11344 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, 11345 pos_token, "ip-version"); 11346 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value = 11347 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, 11348 ip_version, "ipv4#ipv6"); 11349 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_label = 11350 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, 11351 pos_token, "label"); 11352 static cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value = 11353 TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label, 11354 RTE_UINT32); 11355 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src = 11356 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, 11357 pos_token, "ip-src"); 11358 static cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value = 11359 TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src); 11360 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst = 11361 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, 11362 pos_token, "ip-dst"); 11363 static cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value = 11364 TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst); 11365 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan = 11366 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, 11367 pos_token, "vlan-tci"); 11368 static cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value = 11369 TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci, 11370 RTE_UINT16); 11371 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src = 11372 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, 11373 pos_token, "eth-src"); 11374 static cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value = 11375 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, 11376 eth_src); 11377 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst = 11378 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, 11379 pos_token, "eth-dst"); 11380 static cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value = 11381 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, 11382 eth_dst); 11383 11384 static void cmd_set_mplsogre_encap_parsed(void *parsed_result, 11385 __rte_unused struct cmdline *cl, 11386 __rte_unused void *data) 11387 { 11388 struct cmd_set_mplsogre_encap_result *res = parsed_result; 11389 union { 11390 uint32_t mplsogre_label; 11391 uint8_t label[4]; 11392 } id = { 11393 .mplsogre_label = rte_cpu_to_be_32(res->label<<12), 11394 }; 11395 11396 if (strcmp(res->mplsogre, "mplsogre_encap") == 0) 11397 mplsogre_encap_conf.select_vlan = 0; 11398 else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0) 11399 mplsogre_encap_conf.select_vlan = 1; 11400 if (strcmp(res->ip_version, "ipv4") == 0) 11401 mplsogre_encap_conf.select_ipv4 = 1; 11402 else if (strcmp(res->ip_version, "ipv6") == 0) 11403 mplsogre_encap_conf.select_ipv4 = 0; 11404 else 11405 return; 11406 rte_memcpy(mplsogre_encap_conf.label, &id.label, 3); 11407 if (mplsogre_encap_conf.select_ipv4) { 11408 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src); 11409 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst); 11410 } else { 11411 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src); 11412 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst); 11413 } 11414 if (mplsogre_encap_conf.select_vlan) 11415 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci); 11416 rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes, 11417 RTE_ETHER_ADDR_LEN); 11418 rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes, 11419 RTE_ETHER_ADDR_LEN); 11420 } 11421 11422 static cmdline_parse_inst_t cmd_set_mplsogre_encap = { 11423 .f = cmd_set_mplsogre_encap_parsed, 11424 .data = NULL, 11425 .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>" 11426 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>" 11427 " eth-dst <eth-dst>", 11428 .tokens = { 11429 (void *)&cmd_set_mplsogre_encap_set, 11430 (void *)&cmd_set_mplsogre_encap_mplsogre_encap, 11431 (void *)&cmd_set_mplsogre_encap_ip_version, 11432 (void *)&cmd_set_mplsogre_encap_ip_version_value, 11433 (void *)&cmd_set_mplsogre_encap_label, 11434 (void *)&cmd_set_mplsogre_encap_label_value, 11435 (void *)&cmd_set_mplsogre_encap_ip_src, 11436 (void *)&cmd_set_mplsogre_encap_ip_src_value, 11437 (void *)&cmd_set_mplsogre_encap_ip_dst, 11438 (void *)&cmd_set_mplsogre_encap_ip_dst_value, 11439 (void *)&cmd_set_mplsogre_encap_eth_src, 11440 (void *)&cmd_set_mplsogre_encap_eth_src_value, 11441 (void *)&cmd_set_mplsogre_encap_eth_dst, 11442 (void *)&cmd_set_mplsogre_encap_eth_dst_value, 11443 NULL, 11444 }, 11445 }; 11446 11447 static cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = { 11448 .f = cmd_set_mplsogre_encap_parsed, 11449 .data = NULL, 11450 .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6" 11451 " label <label> ip-src <ip-src> ip-dst <ip-dst>" 11452 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>", 11453 .tokens = { 11454 (void *)&cmd_set_mplsogre_encap_set, 11455 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan, 11456 (void *)&cmd_set_mplsogre_encap_ip_version, 11457 (void *)&cmd_set_mplsogre_encap_ip_version_value, 11458 (void *)&cmd_set_mplsogre_encap_label, 11459 (void *)&cmd_set_mplsogre_encap_label_value, 11460 (void *)&cmd_set_mplsogre_encap_ip_src, 11461 (void *)&cmd_set_mplsogre_encap_ip_src_value, 11462 (void *)&cmd_set_mplsogre_encap_ip_dst, 11463 (void *)&cmd_set_mplsogre_encap_ip_dst_value, 11464 (void *)&cmd_set_mplsogre_encap_vlan, 11465 (void *)&cmd_set_mplsogre_encap_vlan_value, 11466 (void *)&cmd_set_mplsogre_encap_eth_src, 11467 (void *)&cmd_set_mplsogre_encap_eth_src_value, 11468 (void *)&cmd_set_mplsogre_encap_eth_dst, 11469 (void *)&cmd_set_mplsogre_encap_eth_dst_value, 11470 NULL, 11471 }, 11472 }; 11473 11474 /** Set MPLSoGRE decapsulation details */ 11475 struct cmd_set_mplsogre_decap_result { 11476 cmdline_fixed_string_t set; 11477 cmdline_fixed_string_t mplsogre; 11478 cmdline_fixed_string_t pos_token; 11479 cmdline_fixed_string_t ip_version; 11480 uint32_t vlan_present:1; 11481 }; 11482 11483 static cmdline_parse_token_string_t cmd_set_mplsogre_decap_set = 11484 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set, 11485 "set"); 11486 static cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap = 11487 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre, 11488 "mplsogre_decap"); 11489 static cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan = 11490 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, 11491 mplsogre, "mplsogre_decap-with-vlan"); 11492 static cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version = 11493 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, 11494 pos_token, "ip-version"); 11495 static cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value = 11496 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, 11497 ip_version, "ipv4#ipv6"); 11498 11499 static void cmd_set_mplsogre_decap_parsed(void *parsed_result, 11500 __rte_unused struct cmdline *cl, 11501 __rte_unused void *data) 11502 { 11503 struct cmd_set_mplsogre_decap_result *res = parsed_result; 11504 11505 if (strcmp(res->mplsogre, "mplsogre_decap") == 0) 11506 mplsogre_decap_conf.select_vlan = 0; 11507 else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0) 11508 mplsogre_decap_conf.select_vlan = 1; 11509 if (strcmp(res->ip_version, "ipv4") == 0) 11510 mplsogre_decap_conf.select_ipv4 = 1; 11511 else if (strcmp(res->ip_version, "ipv6") == 0) 11512 mplsogre_decap_conf.select_ipv4 = 0; 11513 } 11514 11515 static cmdline_parse_inst_t cmd_set_mplsogre_decap = { 11516 .f = cmd_set_mplsogre_decap_parsed, 11517 .data = NULL, 11518 .help_str = "set mplsogre_decap ip-version ipv4|ipv6", 11519 .tokens = { 11520 (void *)&cmd_set_mplsogre_decap_set, 11521 (void *)&cmd_set_mplsogre_decap_mplsogre_decap, 11522 (void *)&cmd_set_mplsogre_decap_ip_version, 11523 (void *)&cmd_set_mplsogre_decap_ip_version_value, 11524 NULL, 11525 }, 11526 }; 11527 11528 static cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = { 11529 .f = cmd_set_mplsogre_decap_parsed, 11530 .data = NULL, 11531 .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6", 11532 .tokens = { 11533 (void *)&cmd_set_mplsogre_decap_set, 11534 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan, 11535 (void *)&cmd_set_mplsogre_decap_ip_version, 11536 (void *)&cmd_set_mplsogre_decap_ip_version_value, 11537 NULL, 11538 }, 11539 }; 11540 11541 /** Set MPLSoUDP encapsulation details */ 11542 struct cmd_set_mplsoudp_encap_result { 11543 cmdline_fixed_string_t set; 11544 cmdline_fixed_string_t mplsoudp; 11545 cmdline_fixed_string_t pos_token; 11546 cmdline_fixed_string_t ip_version; 11547 uint32_t vlan_present:1; 11548 uint32_t label; 11549 uint16_t udp_src; 11550 uint16_t udp_dst; 11551 cmdline_ipaddr_t ip_src; 11552 cmdline_ipaddr_t ip_dst; 11553 uint16_t tci; 11554 struct rte_ether_addr eth_src; 11555 struct rte_ether_addr eth_dst; 11556 }; 11557 11558 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set = 11559 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set, 11560 "set"); 11561 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap = 11562 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp, 11563 "mplsoudp_encap"); 11564 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan = 11565 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, 11566 mplsoudp, "mplsoudp_encap-with-vlan"); 11567 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version = 11568 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, 11569 pos_token, "ip-version"); 11570 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value = 11571 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, 11572 ip_version, "ipv4#ipv6"); 11573 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label = 11574 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, 11575 pos_token, "label"); 11576 static cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value = 11577 TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label, 11578 RTE_UINT32); 11579 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src = 11580 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, 11581 pos_token, "udp-src"); 11582 static cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value = 11583 TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src, 11584 RTE_UINT16); 11585 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst = 11586 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, 11587 pos_token, "udp-dst"); 11588 static cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value = 11589 TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst, 11590 RTE_UINT16); 11591 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src = 11592 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, 11593 pos_token, "ip-src"); 11594 static cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value = 11595 TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src); 11596 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst = 11597 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, 11598 pos_token, "ip-dst"); 11599 static cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value = 11600 TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst); 11601 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan = 11602 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, 11603 pos_token, "vlan-tci"); 11604 static cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value = 11605 TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci, 11606 RTE_UINT16); 11607 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src = 11608 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, 11609 pos_token, "eth-src"); 11610 static cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value = 11611 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, 11612 eth_src); 11613 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst = 11614 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, 11615 pos_token, "eth-dst"); 11616 static cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value = 11617 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, 11618 eth_dst); 11619 11620 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result, 11621 __rte_unused struct cmdline *cl, 11622 __rte_unused void *data) 11623 { 11624 struct cmd_set_mplsoudp_encap_result *res = parsed_result; 11625 union { 11626 uint32_t mplsoudp_label; 11627 uint8_t label[4]; 11628 } id = { 11629 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12), 11630 }; 11631 11632 if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0) 11633 mplsoudp_encap_conf.select_vlan = 0; 11634 else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0) 11635 mplsoudp_encap_conf.select_vlan = 1; 11636 if (strcmp(res->ip_version, "ipv4") == 0) 11637 mplsoudp_encap_conf.select_ipv4 = 1; 11638 else if (strcmp(res->ip_version, "ipv6") == 0) 11639 mplsoudp_encap_conf.select_ipv4 = 0; 11640 else 11641 return; 11642 rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3); 11643 mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src); 11644 mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst); 11645 if (mplsoudp_encap_conf.select_ipv4) { 11646 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src); 11647 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst); 11648 } else { 11649 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src); 11650 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst); 11651 } 11652 if (mplsoudp_encap_conf.select_vlan) 11653 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci); 11654 rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes, 11655 RTE_ETHER_ADDR_LEN); 11656 rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes, 11657 RTE_ETHER_ADDR_LEN); 11658 } 11659 11660 static cmdline_parse_inst_t cmd_set_mplsoudp_encap = { 11661 .f = cmd_set_mplsoudp_encap_parsed, 11662 .data = NULL, 11663 .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>" 11664 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>" 11665 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>", 11666 .tokens = { 11667 (void *)&cmd_set_mplsoudp_encap_set, 11668 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap, 11669 (void *)&cmd_set_mplsoudp_encap_ip_version, 11670 (void *)&cmd_set_mplsoudp_encap_ip_version_value, 11671 (void *)&cmd_set_mplsoudp_encap_label, 11672 (void *)&cmd_set_mplsoudp_encap_label_value, 11673 (void *)&cmd_set_mplsoudp_encap_udp_src, 11674 (void *)&cmd_set_mplsoudp_encap_udp_src_value, 11675 (void *)&cmd_set_mplsoudp_encap_udp_dst, 11676 (void *)&cmd_set_mplsoudp_encap_udp_dst_value, 11677 (void *)&cmd_set_mplsoudp_encap_ip_src, 11678 (void *)&cmd_set_mplsoudp_encap_ip_src_value, 11679 (void *)&cmd_set_mplsoudp_encap_ip_dst, 11680 (void *)&cmd_set_mplsoudp_encap_ip_dst_value, 11681 (void *)&cmd_set_mplsoudp_encap_eth_src, 11682 (void *)&cmd_set_mplsoudp_encap_eth_src_value, 11683 (void *)&cmd_set_mplsoudp_encap_eth_dst, 11684 (void *)&cmd_set_mplsoudp_encap_eth_dst_value, 11685 NULL, 11686 }, 11687 }; 11688 11689 static cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = { 11690 .f = cmd_set_mplsoudp_encap_parsed, 11691 .data = NULL, 11692 .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6" 11693 " label <label> udp-src <udp-src> udp-dst <udp-dst>" 11694 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>" 11695 " eth-src <eth-src> eth-dst <eth-dst>", 11696 .tokens = { 11697 (void *)&cmd_set_mplsoudp_encap_set, 11698 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan, 11699 (void *)&cmd_set_mplsoudp_encap_ip_version, 11700 (void *)&cmd_set_mplsoudp_encap_ip_version_value, 11701 (void *)&cmd_set_mplsoudp_encap_label, 11702 (void *)&cmd_set_mplsoudp_encap_label_value, 11703 (void *)&cmd_set_mplsoudp_encap_udp_src, 11704 (void *)&cmd_set_mplsoudp_encap_udp_src_value, 11705 (void *)&cmd_set_mplsoudp_encap_udp_dst, 11706 (void *)&cmd_set_mplsoudp_encap_udp_dst_value, 11707 (void *)&cmd_set_mplsoudp_encap_ip_src, 11708 (void *)&cmd_set_mplsoudp_encap_ip_src_value, 11709 (void *)&cmd_set_mplsoudp_encap_ip_dst, 11710 (void *)&cmd_set_mplsoudp_encap_ip_dst_value, 11711 (void *)&cmd_set_mplsoudp_encap_vlan, 11712 (void *)&cmd_set_mplsoudp_encap_vlan_value, 11713 (void *)&cmd_set_mplsoudp_encap_eth_src, 11714 (void *)&cmd_set_mplsoudp_encap_eth_src_value, 11715 (void *)&cmd_set_mplsoudp_encap_eth_dst, 11716 (void *)&cmd_set_mplsoudp_encap_eth_dst_value, 11717 NULL, 11718 }, 11719 }; 11720 11721 /** Set MPLSoUDP decapsulation details */ 11722 struct cmd_set_mplsoudp_decap_result { 11723 cmdline_fixed_string_t set; 11724 cmdline_fixed_string_t mplsoudp; 11725 cmdline_fixed_string_t pos_token; 11726 cmdline_fixed_string_t ip_version; 11727 uint32_t vlan_present:1; 11728 }; 11729 11730 static cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set = 11731 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set, 11732 "set"); 11733 static cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap = 11734 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp, 11735 "mplsoudp_decap"); 11736 static cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan = 11737 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, 11738 mplsoudp, "mplsoudp_decap-with-vlan"); 11739 static cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version = 11740 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, 11741 pos_token, "ip-version"); 11742 static cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value = 11743 TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, 11744 ip_version, "ipv4#ipv6"); 11745 11746 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result, 11747 __rte_unused struct cmdline *cl, 11748 __rte_unused void *data) 11749 { 11750 struct cmd_set_mplsoudp_decap_result *res = parsed_result; 11751 11752 if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0) 11753 mplsoudp_decap_conf.select_vlan = 0; 11754 else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0) 11755 mplsoudp_decap_conf.select_vlan = 1; 11756 if (strcmp(res->ip_version, "ipv4") == 0) 11757 mplsoudp_decap_conf.select_ipv4 = 1; 11758 else if (strcmp(res->ip_version, "ipv6") == 0) 11759 mplsoudp_decap_conf.select_ipv4 = 0; 11760 } 11761 11762 static cmdline_parse_inst_t cmd_set_mplsoudp_decap = { 11763 .f = cmd_set_mplsoudp_decap_parsed, 11764 .data = NULL, 11765 .help_str = "set mplsoudp_decap ip-version ipv4|ipv6", 11766 .tokens = { 11767 (void *)&cmd_set_mplsoudp_decap_set, 11768 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap, 11769 (void *)&cmd_set_mplsoudp_decap_ip_version, 11770 (void *)&cmd_set_mplsoudp_decap_ip_version_value, 11771 NULL, 11772 }, 11773 }; 11774 11775 static cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = { 11776 .f = cmd_set_mplsoudp_decap_parsed, 11777 .data = NULL, 11778 .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6", 11779 .tokens = { 11780 (void *)&cmd_set_mplsoudp_decap_set, 11781 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan, 11782 (void *)&cmd_set_mplsoudp_decap_ip_version, 11783 (void *)&cmd_set_mplsoudp_decap_ip_version_value, 11784 NULL, 11785 }, 11786 }; 11787 11788 /** Set connection tracking object common details */ 11789 struct cmd_set_conntrack_common_result { 11790 cmdline_fixed_string_t set; 11791 cmdline_fixed_string_t conntrack; 11792 cmdline_fixed_string_t common; 11793 cmdline_fixed_string_t peer; 11794 cmdline_fixed_string_t is_orig; 11795 cmdline_fixed_string_t enable; 11796 cmdline_fixed_string_t live; 11797 cmdline_fixed_string_t sack; 11798 cmdline_fixed_string_t cack; 11799 cmdline_fixed_string_t last_dir; 11800 cmdline_fixed_string_t liberal; 11801 cmdline_fixed_string_t state; 11802 cmdline_fixed_string_t max_ack_win; 11803 cmdline_fixed_string_t retrans; 11804 cmdline_fixed_string_t last_win; 11805 cmdline_fixed_string_t last_seq; 11806 cmdline_fixed_string_t last_ack; 11807 cmdline_fixed_string_t last_end; 11808 cmdline_fixed_string_t last_index; 11809 uint8_t stat; 11810 uint8_t factor; 11811 uint16_t peer_port; 11812 uint32_t is_original; 11813 uint32_t en; 11814 uint32_t is_live; 11815 uint32_t s_ack; 11816 uint32_t c_ack; 11817 uint32_t ld; 11818 uint32_t lb; 11819 uint8_t re_num; 11820 uint8_t li; 11821 uint16_t lw; 11822 uint32_t ls; 11823 uint32_t la; 11824 uint32_t le; 11825 }; 11826 11827 static cmdline_parse_token_string_t cmd_set_conntrack_set = 11828 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result, 11829 set, "set"); 11830 static cmdline_parse_token_string_t cmd_set_conntrack_conntrack = 11831 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result, 11832 conntrack, "conntrack"); 11833 static cmdline_parse_token_string_t cmd_set_conntrack_common_com = 11834 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result, 11835 common, "com"); 11836 static cmdline_parse_token_string_t cmd_set_conntrack_common_peer = 11837 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result, 11838 peer, "peer"); 11839 static cmdline_parse_token_num_t cmd_set_conntrack_common_peer_value = 11840 TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result, 11841 peer_port, RTE_UINT16); 11842 static cmdline_parse_token_string_t cmd_set_conntrack_common_is_orig = 11843 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result, 11844 is_orig, "is_orig"); 11845 static cmdline_parse_token_num_t cmd_set_conntrack_common_is_orig_value = 11846 TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result, 11847 is_original, RTE_UINT32); 11848 static cmdline_parse_token_string_t cmd_set_conntrack_common_enable = 11849 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result, 11850 enable, "enable"); 11851 static cmdline_parse_token_num_t cmd_set_conntrack_common_enable_value = 11852 TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result, 11853 en, RTE_UINT32); 11854 static cmdline_parse_token_string_t cmd_set_conntrack_common_live = 11855 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result, 11856 live, "live"); 11857 static cmdline_parse_token_num_t cmd_set_conntrack_common_live_value = 11858 TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result, 11859 is_live, RTE_UINT32); 11860 static cmdline_parse_token_string_t cmd_set_conntrack_common_sack = 11861 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result, 11862 sack, "sack"); 11863 static cmdline_parse_token_num_t cmd_set_conntrack_common_sack_value = 11864 TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result, 11865 s_ack, RTE_UINT32); 11866 static cmdline_parse_token_string_t cmd_set_conntrack_common_cack = 11867 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result, 11868 cack, "cack"); 11869 static cmdline_parse_token_num_t cmd_set_conntrack_common_cack_value = 11870 TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result, 11871 c_ack, RTE_UINT32); 11872 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_dir = 11873 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result, 11874 last_dir, "last_dir"); 11875 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_dir_value = 11876 TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result, 11877 ld, RTE_UINT32); 11878 static cmdline_parse_token_string_t cmd_set_conntrack_common_liberal = 11879 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result, 11880 liberal, "liberal"); 11881 static cmdline_parse_token_num_t cmd_set_conntrack_common_liberal_value = 11882 TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result, 11883 lb, RTE_UINT32); 11884 static cmdline_parse_token_string_t cmd_set_conntrack_common_state = 11885 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result, 11886 state, "state"); 11887 static cmdline_parse_token_num_t cmd_set_conntrack_common_state_value = 11888 TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result, 11889 stat, RTE_UINT8); 11890 static cmdline_parse_token_string_t cmd_set_conntrack_common_max_ackwin = 11891 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result, 11892 max_ack_win, "max_ack_win"); 11893 static cmdline_parse_token_num_t cmd_set_conntrack_common_max_ackwin_value = 11894 TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result, 11895 factor, RTE_UINT8); 11896 static cmdline_parse_token_string_t cmd_set_conntrack_common_retrans = 11897 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result, 11898 retrans, "r_lim"); 11899 static cmdline_parse_token_num_t cmd_set_conntrack_common_retrans_value = 11900 TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result, 11901 re_num, RTE_UINT8); 11902 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_win = 11903 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result, 11904 last_win, "last_win"); 11905 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_win_value = 11906 TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result, 11907 lw, RTE_UINT16); 11908 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_seq = 11909 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result, 11910 last_seq, "last_seq"); 11911 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_seq_value = 11912 TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result, 11913 ls, RTE_UINT32); 11914 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_ack = 11915 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result, 11916 last_ack, "last_ack"); 11917 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_ack_value = 11918 TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result, 11919 la, RTE_UINT32); 11920 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_end = 11921 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result, 11922 last_end, "last_end"); 11923 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_end_value = 11924 TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result, 11925 le, RTE_UINT32); 11926 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_index = 11927 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result, 11928 last_index, "last_index"); 11929 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_index_value = 11930 TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result, 11931 li, RTE_UINT8); 11932 11933 static void cmd_set_conntrack_common_parsed(void *parsed_result, 11934 __rte_unused struct cmdline *cl, 11935 __rte_unused void *data) 11936 { 11937 struct cmd_set_conntrack_common_result *res = parsed_result; 11938 11939 /* No need to swap to big endian. */ 11940 conntrack_context.peer_port = res->peer_port; 11941 conntrack_context.is_original_dir = res->is_original; 11942 conntrack_context.enable = res->en; 11943 conntrack_context.live_connection = res->is_live; 11944 conntrack_context.selective_ack = res->s_ack; 11945 conntrack_context.challenge_ack_passed = res->c_ack; 11946 conntrack_context.last_direction = res->ld; 11947 conntrack_context.liberal_mode = res->lb; 11948 conntrack_context.state = (enum rte_flow_conntrack_state)res->stat; 11949 conntrack_context.max_ack_window = res->factor; 11950 conntrack_context.retransmission_limit = res->re_num; 11951 conntrack_context.last_window = res->lw; 11952 conntrack_context.last_index = 11953 (enum rte_flow_conntrack_tcp_last_index)res->li; 11954 conntrack_context.last_seq = res->ls; 11955 conntrack_context.last_ack = res->la; 11956 conntrack_context.last_end = res->le; 11957 } 11958 11959 static cmdline_parse_inst_t cmd_set_conntrack_common = { 11960 .f = cmd_set_conntrack_common_parsed, 11961 .data = NULL, 11962 .help_str = "set conntrack com peer <port_id> is_orig <dir> enable <en>" 11963 " live <ack_seen> sack <en> cack <passed> last_dir <dir>" 11964 " liberal <en> state <s> max_ack_win <factor> r_lim <num>" 11965 " last_win <win> last_seq <seq> last_ack <ack> last_end <end>" 11966 " last_index <flag>", 11967 .tokens = { 11968 (void *)&cmd_set_conntrack_set, 11969 (void *)&cmd_set_conntrack_conntrack, 11970 (void *)&cmd_set_conntrack_common_com, 11971 (void *)&cmd_set_conntrack_common_peer, 11972 (void *)&cmd_set_conntrack_common_peer_value, 11973 (void *)&cmd_set_conntrack_common_is_orig, 11974 (void *)&cmd_set_conntrack_common_is_orig_value, 11975 (void *)&cmd_set_conntrack_common_enable, 11976 (void *)&cmd_set_conntrack_common_enable_value, 11977 (void *)&cmd_set_conntrack_common_live, 11978 (void *)&cmd_set_conntrack_common_live_value, 11979 (void *)&cmd_set_conntrack_common_sack, 11980 (void *)&cmd_set_conntrack_common_sack_value, 11981 (void *)&cmd_set_conntrack_common_cack, 11982 (void *)&cmd_set_conntrack_common_cack_value, 11983 (void *)&cmd_set_conntrack_common_last_dir, 11984 (void *)&cmd_set_conntrack_common_last_dir_value, 11985 (void *)&cmd_set_conntrack_common_liberal, 11986 (void *)&cmd_set_conntrack_common_liberal_value, 11987 (void *)&cmd_set_conntrack_common_state, 11988 (void *)&cmd_set_conntrack_common_state_value, 11989 (void *)&cmd_set_conntrack_common_max_ackwin, 11990 (void *)&cmd_set_conntrack_common_max_ackwin_value, 11991 (void *)&cmd_set_conntrack_common_retrans, 11992 (void *)&cmd_set_conntrack_common_retrans_value, 11993 (void *)&cmd_set_conntrack_common_last_win, 11994 (void *)&cmd_set_conntrack_common_last_win_value, 11995 (void *)&cmd_set_conntrack_common_last_seq, 11996 (void *)&cmd_set_conntrack_common_last_seq_value, 11997 (void *)&cmd_set_conntrack_common_last_ack, 11998 (void *)&cmd_set_conntrack_common_last_ack_value, 11999 (void *)&cmd_set_conntrack_common_last_end, 12000 (void *)&cmd_set_conntrack_common_last_end_value, 12001 (void *)&cmd_set_conntrack_common_last_index, 12002 (void *)&cmd_set_conntrack_common_last_index_value, 12003 NULL, 12004 }, 12005 }; 12006 12007 /** Set connection tracking object both directions' details */ 12008 struct cmd_set_conntrack_dir_result { 12009 cmdline_fixed_string_t set; 12010 cmdline_fixed_string_t conntrack; 12011 cmdline_fixed_string_t dir; 12012 cmdline_fixed_string_t scale; 12013 cmdline_fixed_string_t fin; 12014 cmdline_fixed_string_t ack_seen; 12015 cmdline_fixed_string_t unack; 12016 cmdline_fixed_string_t sent_end; 12017 cmdline_fixed_string_t reply_end; 12018 cmdline_fixed_string_t max_win; 12019 cmdline_fixed_string_t max_ack; 12020 uint32_t factor; 12021 uint32_t f; 12022 uint32_t as; 12023 uint32_t un; 12024 uint32_t se; 12025 uint32_t re; 12026 uint32_t mw; 12027 uint32_t ma; 12028 }; 12029 12030 static cmdline_parse_token_string_t cmd_set_conntrack_dir_dir = 12031 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result, 12032 dir, "orig#rply"); 12033 static cmdline_parse_token_string_t cmd_set_conntrack_dir_scale = 12034 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result, 12035 scale, "scale"); 12036 static cmdline_parse_token_num_t cmd_set_conntrack_dir_scale_value = 12037 TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result, 12038 factor, RTE_UINT32); 12039 static cmdline_parse_token_string_t cmd_set_conntrack_dir_fin = 12040 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result, 12041 fin, "fin"); 12042 static cmdline_parse_token_num_t cmd_set_conntrack_dir_fin_value = 12043 TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result, 12044 f, RTE_UINT32); 12045 static cmdline_parse_token_string_t cmd_set_conntrack_dir_ack = 12046 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result, 12047 ack_seen, "acked"); 12048 static cmdline_parse_token_num_t cmd_set_conntrack_dir_ack_value = 12049 TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result, 12050 as, RTE_UINT32); 12051 static cmdline_parse_token_string_t cmd_set_conntrack_dir_unack_data = 12052 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result, 12053 unack, "unack_data"); 12054 static cmdline_parse_token_num_t cmd_set_conntrack_dir_unack_data_value = 12055 TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result, 12056 un, RTE_UINT32); 12057 static cmdline_parse_token_string_t cmd_set_conntrack_dir_sent_end = 12058 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result, 12059 sent_end, "sent_end"); 12060 static cmdline_parse_token_num_t cmd_set_conntrack_dir_sent_end_value = 12061 TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result, 12062 se, RTE_UINT32); 12063 static cmdline_parse_token_string_t cmd_set_conntrack_dir_reply_end = 12064 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result, 12065 reply_end, "reply_end"); 12066 static cmdline_parse_token_num_t cmd_set_conntrack_dir_reply_end_value = 12067 TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result, 12068 re, RTE_UINT32); 12069 static cmdline_parse_token_string_t cmd_set_conntrack_dir_max_win = 12070 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result, 12071 max_win, "max_win"); 12072 static cmdline_parse_token_num_t cmd_set_conntrack_dir_max_win_value = 12073 TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result, 12074 mw, RTE_UINT32); 12075 static cmdline_parse_token_string_t cmd_set_conntrack_dir_max_ack = 12076 TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result, 12077 max_ack, "max_ack"); 12078 static cmdline_parse_token_num_t cmd_set_conntrack_dir_max_ack_value = 12079 TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result, 12080 ma, RTE_UINT32); 12081 12082 static void cmd_set_conntrack_dir_parsed(void *parsed_result, 12083 __rte_unused struct cmdline *cl, 12084 __rte_unused void *data) 12085 { 12086 struct cmd_set_conntrack_dir_result *res = parsed_result; 12087 struct rte_flow_tcp_dir_param *dir = NULL; 12088 12089 if (strcmp(res->dir, "orig") == 0) 12090 dir = &conntrack_context.original_dir; 12091 else if (strcmp(res->dir, "rply") == 0) 12092 dir = &conntrack_context.reply_dir; 12093 else 12094 return; 12095 dir->scale = res->factor; 12096 dir->close_initiated = res->f; 12097 dir->last_ack_seen = res->as; 12098 dir->data_unacked = res->un; 12099 dir->sent_end = res->se; 12100 dir->reply_end = res->re; 12101 dir->max_ack = res->ma; 12102 dir->max_win = res->mw; 12103 } 12104 12105 static cmdline_parse_inst_t cmd_set_conntrack_dir = { 12106 .f = cmd_set_conntrack_dir_parsed, 12107 .data = NULL, 12108 .help_str = "set conntrack orig|rply scale <factor> fin <sent>" 12109 " acked <seen> unack_data <unack> sent_end <sent>" 12110 " reply_end <reply> max_win <win> max_ack <ack>", 12111 .tokens = { 12112 (void *)&cmd_set_conntrack_set, 12113 (void *)&cmd_set_conntrack_conntrack, 12114 (void *)&cmd_set_conntrack_dir_dir, 12115 (void *)&cmd_set_conntrack_dir_scale, 12116 (void *)&cmd_set_conntrack_dir_scale_value, 12117 (void *)&cmd_set_conntrack_dir_fin, 12118 (void *)&cmd_set_conntrack_dir_fin_value, 12119 (void *)&cmd_set_conntrack_dir_ack, 12120 (void *)&cmd_set_conntrack_dir_ack_value, 12121 (void *)&cmd_set_conntrack_dir_unack_data, 12122 (void *)&cmd_set_conntrack_dir_unack_data_value, 12123 (void *)&cmd_set_conntrack_dir_sent_end, 12124 (void *)&cmd_set_conntrack_dir_sent_end_value, 12125 (void *)&cmd_set_conntrack_dir_reply_end, 12126 (void *)&cmd_set_conntrack_dir_reply_end_value, 12127 (void *)&cmd_set_conntrack_dir_max_win, 12128 (void *)&cmd_set_conntrack_dir_max_win_value, 12129 (void *)&cmd_set_conntrack_dir_max_ack, 12130 (void *)&cmd_set_conntrack_dir_max_ack_value, 12131 NULL, 12132 }, 12133 }; 12134 12135 /* show vf stats */ 12136 12137 /* Common result structure for show vf stats */ 12138 struct cmd_show_vf_stats_result { 12139 cmdline_fixed_string_t show; 12140 cmdline_fixed_string_t vf; 12141 cmdline_fixed_string_t stats; 12142 portid_t port_id; 12143 uint16_t vf_id; 12144 }; 12145 12146 /* Common CLI fields show vf stats*/ 12147 static cmdline_parse_token_string_t cmd_show_vf_stats_show = 12148 TOKEN_STRING_INITIALIZER 12149 (struct cmd_show_vf_stats_result, 12150 show, "show"); 12151 static cmdline_parse_token_string_t cmd_show_vf_stats_vf = 12152 TOKEN_STRING_INITIALIZER 12153 (struct cmd_show_vf_stats_result, 12154 vf, "vf"); 12155 static cmdline_parse_token_string_t cmd_show_vf_stats_stats = 12156 TOKEN_STRING_INITIALIZER 12157 (struct cmd_show_vf_stats_result, 12158 stats, "stats"); 12159 static cmdline_parse_token_num_t cmd_show_vf_stats_port_id = 12160 TOKEN_NUM_INITIALIZER 12161 (struct cmd_show_vf_stats_result, 12162 port_id, RTE_UINT16); 12163 static cmdline_parse_token_num_t cmd_show_vf_stats_vf_id = 12164 TOKEN_NUM_INITIALIZER 12165 (struct cmd_show_vf_stats_result, 12166 vf_id, RTE_UINT16); 12167 12168 static void 12169 cmd_show_vf_stats_parsed( 12170 void *parsed_result, 12171 __rte_unused struct cmdline *cl, 12172 __rte_unused void *data) 12173 { 12174 struct cmd_show_vf_stats_result *res = parsed_result; 12175 struct rte_eth_stats stats; 12176 int ret = -ENOTSUP; 12177 static const char *nic_stats_border = "########################"; 12178 12179 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12180 return; 12181 12182 memset(&stats, 0, sizeof(stats)); 12183 12184 #ifdef RTE_NET_I40E 12185 if (ret == -ENOTSUP) 12186 ret = rte_pmd_i40e_get_vf_stats(res->port_id, 12187 res->vf_id, 12188 &stats); 12189 #endif 12190 #ifdef RTE_NET_BNXT 12191 if (ret == -ENOTSUP) 12192 ret = rte_pmd_bnxt_get_vf_stats(res->port_id, 12193 res->vf_id, 12194 &stats); 12195 #endif 12196 12197 switch (ret) { 12198 case 0: 12199 break; 12200 case -EINVAL: 12201 fprintf(stderr, "invalid vf_id %d\n", res->vf_id); 12202 break; 12203 case -ENODEV: 12204 fprintf(stderr, "invalid port_id %d\n", res->port_id); 12205 break; 12206 case -ENOTSUP: 12207 fprintf(stderr, "function not implemented\n"); 12208 break; 12209 default: 12210 fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); 12211 } 12212 12213 printf("\n %s NIC statistics for port %-2d vf %-2d %s\n", 12214 nic_stats_border, res->port_id, res->vf_id, nic_stats_border); 12215 12216 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: " 12217 "%-"PRIu64"\n", 12218 stats.ipackets, stats.imissed, stats.ibytes); 12219 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors); 12220 printf(" RX-nombuf: %-10"PRIu64"\n", 12221 stats.rx_nombuf); 12222 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: " 12223 "%-"PRIu64"\n", 12224 stats.opackets, stats.oerrors, stats.obytes); 12225 12226 printf(" %s############################%s\n", 12227 nic_stats_border, nic_stats_border); 12228 } 12229 12230 static cmdline_parse_inst_t cmd_show_vf_stats = { 12231 .f = cmd_show_vf_stats_parsed, 12232 .data = NULL, 12233 .help_str = "show vf stats <port_id> <vf_id>", 12234 .tokens = { 12235 (void *)&cmd_show_vf_stats_show, 12236 (void *)&cmd_show_vf_stats_vf, 12237 (void *)&cmd_show_vf_stats_stats, 12238 (void *)&cmd_show_vf_stats_port_id, 12239 (void *)&cmd_show_vf_stats_vf_id, 12240 NULL, 12241 }, 12242 }; 12243 12244 /* clear vf stats */ 12245 12246 /* Common result structure for clear vf stats */ 12247 struct cmd_clear_vf_stats_result { 12248 cmdline_fixed_string_t clear; 12249 cmdline_fixed_string_t vf; 12250 cmdline_fixed_string_t stats; 12251 portid_t port_id; 12252 uint16_t vf_id; 12253 }; 12254 12255 /* Common CLI fields clear vf stats*/ 12256 static cmdline_parse_token_string_t cmd_clear_vf_stats_clear = 12257 TOKEN_STRING_INITIALIZER 12258 (struct cmd_clear_vf_stats_result, 12259 clear, "clear"); 12260 static cmdline_parse_token_string_t cmd_clear_vf_stats_vf = 12261 TOKEN_STRING_INITIALIZER 12262 (struct cmd_clear_vf_stats_result, 12263 vf, "vf"); 12264 static cmdline_parse_token_string_t cmd_clear_vf_stats_stats = 12265 TOKEN_STRING_INITIALIZER 12266 (struct cmd_clear_vf_stats_result, 12267 stats, "stats"); 12268 static cmdline_parse_token_num_t cmd_clear_vf_stats_port_id = 12269 TOKEN_NUM_INITIALIZER 12270 (struct cmd_clear_vf_stats_result, 12271 port_id, RTE_UINT16); 12272 static cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id = 12273 TOKEN_NUM_INITIALIZER 12274 (struct cmd_clear_vf_stats_result, 12275 vf_id, RTE_UINT16); 12276 12277 static void 12278 cmd_clear_vf_stats_parsed( 12279 void *parsed_result, 12280 __rte_unused struct cmdline *cl, 12281 __rte_unused void *data) 12282 { 12283 struct cmd_clear_vf_stats_result *res = parsed_result; 12284 int ret = -ENOTSUP; 12285 12286 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12287 return; 12288 12289 #ifdef RTE_NET_I40E 12290 if (ret == -ENOTSUP) 12291 ret = rte_pmd_i40e_reset_vf_stats(res->port_id, 12292 res->vf_id); 12293 #endif 12294 #ifdef RTE_NET_BNXT 12295 if (ret == -ENOTSUP) 12296 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id, 12297 res->vf_id); 12298 #endif 12299 12300 switch (ret) { 12301 case 0: 12302 break; 12303 case -EINVAL: 12304 fprintf(stderr, "invalid vf_id %d\n", res->vf_id); 12305 break; 12306 case -ENODEV: 12307 fprintf(stderr, "invalid port_id %d\n", res->port_id); 12308 break; 12309 case -ENOTSUP: 12310 fprintf(stderr, "function not implemented\n"); 12311 break; 12312 default: 12313 fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); 12314 } 12315 } 12316 12317 static cmdline_parse_inst_t cmd_clear_vf_stats = { 12318 .f = cmd_clear_vf_stats_parsed, 12319 .data = NULL, 12320 .help_str = "clear vf stats <port_id> <vf_id>", 12321 .tokens = { 12322 (void *)&cmd_clear_vf_stats_clear, 12323 (void *)&cmd_clear_vf_stats_vf, 12324 (void *)&cmd_clear_vf_stats_stats, 12325 (void *)&cmd_clear_vf_stats_port_id, 12326 (void *)&cmd_clear_vf_stats_vf_id, 12327 NULL, 12328 }, 12329 }; 12330 12331 /* Common result structure for file commands */ 12332 struct cmd_cmdfile_result { 12333 cmdline_fixed_string_t load; 12334 cmdline_fixed_string_t filename; 12335 }; 12336 12337 /* Common CLI fields for file commands */ 12338 static cmdline_parse_token_string_t cmd_load_cmdfile = 12339 TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load"); 12340 static cmdline_parse_token_string_t cmd_load_cmdfile_filename = 12341 TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL); 12342 12343 static void 12344 cmd_load_from_file_parsed( 12345 void *parsed_result, 12346 __rte_unused struct cmdline *cl, 12347 __rte_unused void *data) 12348 { 12349 struct cmd_cmdfile_result *res = parsed_result; 12350 12351 cmdline_read_from_file(res->filename); 12352 } 12353 12354 static cmdline_parse_inst_t cmd_load_from_file = { 12355 .f = cmd_load_from_file_parsed, 12356 .data = NULL, 12357 .help_str = "load <filename>", 12358 .tokens = { 12359 (void *)&cmd_load_cmdfile, 12360 (void *)&cmd_load_cmdfile_filename, 12361 NULL, 12362 }, 12363 }; 12364 12365 /* Get Rx offloads capabilities */ 12366 struct cmd_rx_offload_get_capa_result { 12367 cmdline_fixed_string_t show; 12368 cmdline_fixed_string_t port; 12369 portid_t port_id; 12370 cmdline_fixed_string_t rx_offload; 12371 cmdline_fixed_string_t capabilities; 12372 }; 12373 12374 static cmdline_parse_token_string_t cmd_rx_offload_get_capa_show = 12375 TOKEN_STRING_INITIALIZER 12376 (struct cmd_rx_offload_get_capa_result, 12377 show, "show"); 12378 static cmdline_parse_token_string_t cmd_rx_offload_get_capa_port = 12379 TOKEN_STRING_INITIALIZER 12380 (struct cmd_rx_offload_get_capa_result, 12381 port, "port"); 12382 static cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id = 12383 TOKEN_NUM_INITIALIZER 12384 (struct cmd_rx_offload_get_capa_result, 12385 port_id, RTE_UINT16); 12386 static cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload = 12387 TOKEN_STRING_INITIALIZER 12388 (struct cmd_rx_offload_get_capa_result, 12389 rx_offload, "rx_offload"); 12390 static cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities = 12391 TOKEN_STRING_INITIALIZER 12392 (struct cmd_rx_offload_get_capa_result, 12393 capabilities, "capabilities"); 12394 12395 static void 12396 print_rx_offloads(uint64_t offloads) 12397 { 12398 uint64_t single_offload; 12399 int begin; 12400 int end; 12401 int bit; 12402 12403 if (offloads == 0) 12404 return; 12405 12406 begin = __builtin_ctzll(offloads); 12407 end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads); 12408 12409 single_offload = 1ULL << begin; 12410 for (bit = begin; bit < end; bit++) { 12411 if (offloads & single_offload) 12412 printf(" %s", 12413 rte_eth_dev_rx_offload_name(single_offload)); 12414 single_offload <<= 1; 12415 } 12416 } 12417 12418 static void 12419 cmd_rx_offload_get_capa_parsed( 12420 void *parsed_result, 12421 __rte_unused struct cmdline *cl, 12422 __rte_unused void *data) 12423 { 12424 struct cmd_rx_offload_get_capa_result *res = parsed_result; 12425 struct rte_eth_dev_info dev_info; 12426 portid_t port_id = res->port_id; 12427 uint64_t queue_offloads; 12428 uint64_t port_offloads; 12429 int ret; 12430 12431 ret = eth_dev_info_get_print_err(port_id, &dev_info); 12432 if (ret != 0) 12433 return; 12434 12435 queue_offloads = dev_info.rx_queue_offload_capa; 12436 port_offloads = dev_info.rx_offload_capa ^ queue_offloads; 12437 12438 printf("Rx Offloading Capabilities of port %d :\n", port_id); 12439 printf(" Per Queue :"); 12440 print_rx_offloads(queue_offloads); 12441 12442 printf("\n"); 12443 printf(" Per Port :"); 12444 print_rx_offloads(port_offloads); 12445 printf("\n\n"); 12446 } 12447 12448 static cmdline_parse_inst_t cmd_rx_offload_get_capa = { 12449 .f = cmd_rx_offload_get_capa_parsed, 12450 .data = NULL, 12451 .help_str = "show port <port_id> rx_offload capabilities", 12452 .tokens = { 12453 (void *)&cmd_rx_offload_get_capa_show, 12454 (void *)&cmd_rx_offload_get_capa_port, 12455 (void *)&cmd_rx_offload_get_capa_port_id, 12456 (void *)&cmd_rx_offload_get_capa_rx_offload, 12457 (void *)&cmd_rx_offload_get_capa_capabilities, 12458 NULL, 12459 } 12460 }; 12461 12462 /* Get Rx offloads configuration */ 12463 struct cmd_rx_offload_get_configuration_result { 12464 cmdline_fixed_string_t show; 12465 cmdline_fixed_string_t port; 12466 portid_t port_id; 12467 cmdline_fixed_string_t rx_offload; 12468 cmdline_fixed_string_t configuration; 12469 }; 12470 12471 static cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show = 12472 TOKEN_STRING_INITIALIZER 12473 (struct cmd_rx_offload_get_configuration_result, 12474 show, "show"); 12475 static cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port = 12476 TOKEN_STRING_INITIALIZER 12477 (struct cmd_rx_offload_get_configuration_result, 12478 port, "port"); 12479 static cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id = 12480 TOKEN_NUM_INITIALIZER 12481 (struct cmd_rx_offload_get_configuration_result, 12482 port_id, RTE_UINT16); 12483 static cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload = 12484 TOKEN_STRING_INITIALIZER 12485 (struct cmd_rx_offload_get_configuration_result, 12486 rx_offload, "rx_offload"); 12487 static cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration = 12488 TOKEN_STRING_INITIALIZER 12489 (struct cmd_rx_offload_get_configuration_result, 12490 configuration, "configuration"); 12491 12492 static void 12493 cmd_rx_offload_get_configuration_parsed( 12494 void *parsed_result, 12495 __rte_unused struct cmdline *cl, 12496 __rte_unused void *data) 12497 { 12498 struct cmd_rx_offload_get_configuration_result *res = parsed_result; 12499 struct rte_eth_dev_info dev_info; 12500 portid_t port_id = res->port_id; 12501 struct rte_port *port = &ports[port_id]; 12502 struct rte_eth_conf dev_conf; 12503 uint64_t port_offloads; 12504 uint64_t queue_offloads; 12505 uint16_t nb_rx_queues; 12506 int q; 12507 int ret; 12508 12509 printf("Rx Offloading Configuration of port %d :\n", port_id); 12510 12511 ret = eth_dev_conf_get_print_err(port_id, &dev_conf); 12512 if (ret != 0) 12513 return; 12514 12515 port_offloads = dev_conf.rxmode.offloads; 12516 printf(" Port :"); 12517 print_rx_offloads(port_offloads); 12518 printf("\n"); 12519 12520 ret = eth_dev_info_get_print_err(port_id, &dev_info); 12521 if (ret != 0) 12522 return; 12523 12524 nb_rx_queues = dev_info.nb_rx_queues; 12525 for (q = 0; q < nb_rx_queues; q++) { 12526 queue_offloads = port->rxq[q].conf.offloads; 12527 printf(" Queue[%2d] :", q); 12528 print_rx_offloads(queue_offloads); 12529 printf("\n"); 12530 } 12531 printf("\n"); 12532 } 12533 12534 static cmdline_parse_inst_t cmd_rx_offload_get_configuration = { 12535 .f = cmd_rx_offload_get_configuration_parsed, 12536 .data = NULL, 12537 .help_str = "show port <port_id> rx_offload configuration", 12538 .tokens = { 12539 (void *)&cmd_rx_offload_get_configuration_show, 12540 (void *)&cmd_rx_offload_get_configuration_port, 12541 (void *)&cmd_rx_offload_get_configuration_port_id, 12542 (void *)&cmd_rx_offload_get_configuration_rx_offload, 12543 (void *)&cmd_rx_offload_get_configuration_configuration, 12544 NULL, 12545 } 12546 }; 12547 12548 /* Enable/Disable a per port offloading */ 12549 struct cmd_config_per_port_rx_offload_result { 12550 cmdline_fixed_string_t port; 12551 cmdline_fixed_string_t config; 12552 portid_t port_id; 12553 cmdline_fixed_string_t rx_offload; 12554 cmdline_fixed_string_t offload; 12555 cmdline_fixed_string_t on_off; 12556 }; 12557 12558 static cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port = 12559 TOKEN_STRING_INITIALIZER 12560 (struct cmd_config_per_port_rx_offload_result, 12561 port, "port"); 12562 static cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config = 12563 TOKEN_STRING_INITIALIZER 12564 (struct cmd_config_per_port_rx_offload_result, 12565 config, "config"); 12566 static cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id = 12567 TOKEN_NUM_INITIALIZER 12568 (struct cmd_config_per_port_rx_offload_result, 12569 port_id, RTE_UINT16); 12570 static cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload = 12571 TOKEN_STRING_INITIALIZER 12572 (struct cmd_config_per_port_rx_offload_result, 12573 rx_offload, "rx_offload"); 12574 static cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload = 12575 TOKEN_STRING_INITIALIZER 12576 (struct cmd_config_per_port_rx_offload_result, 12577 offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#" 12578 "qinq_strip#outer_ipv4_cksum#macsec_strip#" 12579 "header_split#vlan_filter#vlan_extend#jumbo_frame#" 12580 "scatter#buffer_split#timestamp#security#" 12581 "keep_crc#rss_hash"); 12582 static cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off = 12583 TOKEN_STRING_INITIALIZER 12584 (struct cmd_config_per_port_rx_offload_result, 12585 on_off, "on#off"); 12586 12587 static uint64_t 12588 search_rx_offload(const char *name) 12589 { 12590 uint64_t single_offload; 12591 const char *single_name; 12592 int found = 0; 12593 unsigned int bit; 12594 12595 single_offload = 1; 12596 for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) { 12597 single_name = rte_eth_dev_rx_offload_name(single_offload); 12598 if (!strcasecmp(single_name, name)) { 12599 found = 1; 12600 break; 12601 } 12602 single_offload <<= 1; 12603 } 12604 12605 if (found) 12606 return single_offload; 12607 12608 return 0; 12609 } 12610 12611 static void 12612 cmd_config_per_port_rx_offload_parsed(void *parsed_result, 12613 __rte_unused struct cmdline *cl, 12614 __rte_unused void *data) 12615 { 12616 struct cmd_config_per_port_rx_offload_result *res = parsed_result; 12617 portid_t port_id = res->port_id; 12618 struct rte_eth_dev_info dev_info; 12619 struct rte_port *port = &ports[port_id]; 12620 uint64_t single_offload; 12621 uint16_t nb_rx_queues; 12622 int q; 12623 int ret; 12624 12625 if (port->port_status != RTE_PORT_STOPPED) { 12626 fprintf(stderr, 12627 "Error: Can't config offload when Port %d is not stopped\n", 12628 port_id); 12629 return; 12630 } 12631 12632 single_offload = search_rx_offload(res->offload); 12633 if (single_offload == 0) { 12634 fprintf(stderr, "Unknown offload name: %s\n", res->offload); 12635 return; 12636 } 12637 12638 ret = eth_dev_info_get_print_err(port_id, &dev_info); 12639 if (ret != 0) 12640 return; 12641 12642 nb_rx_queues = dev_info.nb_rx_queues; 12643 if (!strcmp(res->on_off, "on")) { 12644 port->dev_conf.rxmode.offloads |= single_offload; 12645 for (q = 0; q < nb_rx_queues; q++) 12646 port->rxq[q].conf.offloads |= single_offload; 12647 } else { 12648 port->dev_conf.rxmode.offloads &= ~single_offload; 12649 for (q = 0; q < nb_rx_queues; q++) 12650 port->rxq[q].conf.offloads &= ~single_offload; 12651 } 12652 12653 cmd_reconfig_device_queue(port_id, 1, 1); 12654 } 12655 12656 static cmdline_parse_inst_t cmd_config_per_port_rx_offload = { 12657 .f = cmd_config_per_port_rx_offload_parsed, 12658 .data = NULL, 12659 .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|" 12660 "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|" 12661 "macsec_strip|header_split|vlan_filter|vlan_extend|" 12662 "jumbo_frame|scatter|buffer_split|timestamp|security|" 12663 "keep_crc|rss_hash on|off", 12664 .tokens = { 12665 (void *)&cmd_config_per_port_rx_offload_result_port, 12666 (void *)&cmd_config_per_port_rx_offload_result_config, 12667 (void *)&cmd_config_per_port_rx_offload_result_port_id, 12668 (void *)&cmd_config_per_port_rx_offload_result_rx_offload, 12669 (void *)&cmd_config_per_port_rx_offload_result_offload, 12670 (void *)&cmd_config_per_port_rx_offload_result_on_off, 12671 NULL, 12672 } 12673 }; 12674 12675 /* Enable/Disable a per queue offloading */ 12676 struct cmd_config_per_queue_rx_offload_result { 12677 cmdline_fixed_string_t port; 12678 portid_t port_id; 12679 cmdline_fixed_string_t rxq; 12680 uint16_t queue_id; 12681 cmdline_fixed_string_t rx_offload; 12682 cmdline_fixed_string_t offload; 12683 cmdline_fixed_string_t on_off; 12684 }; 12685 12686 static cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port = 12687 TOKEN_STRING_INITIALIZER 12688 (struct cmd_config_per_queue_rx_offload_result, 12689 port, "port"); 12690 static cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id = 12691 TOKEN_NUM_INITIALIZER 12692 (struct cmd_config_per_queue_rx_offload_result, 12693 port_id, RTE_UINT16); 12694 static cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq = 12695 TOKEN_STRING_INITIALIZER 12696 (struct cmd_config_per_queue_rx_offload_result, 12697 rxq, "rxq"); 12698 static cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id = 12699 TOKEN_NUM_INITIALIZER 12700 (struct cmd_config_per_queue_rx_offload_result, 12701 queue_id, RTE_UINT16); 12702 static cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload = 12703 TOKEN_STRING_INITIALIZER 12704 (struct cmd_config_per_queue_rx_offload_result, 12705 rx_offload, "rx_offload"); 12706 static cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload = 12707 TOKEN_STRING_INITIALIZER 12708 (struct cmd_config_per_queue_rx_offload_result, 12709 offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#" 12710 "qinq_strip#outer_ipv4_cksum#macsec_strip#" 12711 "header_split#vlan_filter#vlan_extend#jumbo_frame#" 12712 "scatter#buffer_split#timestamp#security#keep_crc"); 12713 static cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off = 12714 TOKEN_STRING_INITIALIZER 12715 (struct cmd_config_per_queue_rx_offload_result, 12716 on_off, "on#off"); 12717 12718 static void 12719 cmd_config_per_queue_rx_offload_parsed(void *parsed_result, 12720 __rte_unused struct cmdline *cl, 12721 __rte_unused void *data) 12722 { 12723 struct cmd_config_per_queue_rx_offload_result *res = parsed_result; 12724 struct rte_eth_dev_info dev_info; 12725 portid_t port_id = res->port_id; 12726 uint16_t queue_id = res->queue_id; 12727 struct rte_port *port = &ports[port_id]; 12728 uint64_t single_offload; 12729 int ret; 12730 12731 if (port->port_status != RTE_PORT_STOPPED) { 12732 fprintf(stderr, 12733 "Error: Can't config offload when Port %d is not stopped\n", 12734 port_id); 12735 return; 12736 } 12737 12738 ret = eth_dev_info_get_print_err(port_id, &dev_info); 12739 if (ret != 0) 12740 return; 12741 12742 if (queue_id >= dev_info.nb_rx_queues) { 12743 fprintf(stderr, 12744 "Error: input queue_id should be 0 ... %d\n", 12745 dev_info.nb_rx_queues - 1); 12746 return; 12747 } 12748 12749 single_offload = search_rx_offload(res->offload); 12750 if (single_offload == 0) { 12751 fprintf(stderr, "Unknown offload name: %s\n", res->offload); 12752 return; 12753 } 12754 12755 if (!strcmp(res->on_off, "on")) 12756 port->rxq[queue_id].conf.offloads |= single_offload; 12757 else 12758 port->rxq[queue_id].conf.offloads &= ~single_offload; 12759 12760 cmd_reconfig_device_queue(port_id, 1, 1); 12761 } 12762 12763 static cmdline_parse_inst_t cmd_config_per_queue_rx_offload = { 12764 .f = cmd_config_per_queue_rx_offload_parsed, 12765 .data = NULL, 12766 .help_str = "port <port_id> rxq <queue_id> rx_offload " 12767 "vlan_strip|ipv4_cksum|" 12768 "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|" 12769 "macsec_strip|header_split|vlan_filter|vlan_extend|" 12770 "jumbo_frame|scatter|buffer_split|timestamp|security|" 12771 "keep_crc on|off", 12772 .tokens = { 12773 (void *)&cmd_config_per_queue_rx_offload_result_port, 12774 (void *)&cmd_config_per_queue_rx_offload_result_port_id, 12775 (void *)&cmd_config_per_queue_rx_offload_result_rxq, 12776 (void *)&cmd_config_per_queue_rx_offload_result_queue_id, 12777 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload, 12778 (void *)&cmd_config_per_queue_rx_offload_result_offload, 12779 (void *)&cmd_config_per_queue_rx_offload_result_on_off, 12780 NULL, 12781 } 12782 }; 12783 12784 /* Get Tx offloads capabilities */ 12785 struct cmd_tx_offload_get_capa_result { 12786 cmdline_fixed_string_t show; 12787 cmdline_fixed_string_t port; 12788 portid_t port_id; 12789 cmdline_fixed_string_t tx_offload; 12790 cmdline_fixed_string_t capabilities; 12791 }; 12792 12793 static cmdline_parse_token_string_t cmd_tx_offload_get_capa_show = 12794 TOKEN_STRING_INITIALIZER 12795 (struct cmd_tx_offload_get_capa_result, 12796 show, "show"); 12797 static cmdline_parse_token_string_t cmd_tx_offload_get_capa_port = 12798 TOKEN_STRING_INITIALIZER 12799 (struct cmd_tx_offload_get_capa_result, 12800 port, "port"); 12801 static cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id = 12802 TOKEN_NUM_INITIALIZER 12803 (struct cmd_tx_offload_get_capa_result, 12804 port_id, RTE_UINT16); 12805 static cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload = 12806 TOKEN_STRING_INITIALIZER 12807 (struct cmd_tx_offload_get_capa_result, 12808 tx_offload, "tx_offload"); 12809 static cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities = 12810 TOKEN_STRING_INITIALIZER 12811 (struct cmd_tx_offload_get_capa_result, 12812 capabilities, "capabilities"); 12813 12814 static void 12815 print_tx_offloads(uint64_t offloads) 12816 { 12817 uint64_t single_offload; 12818 int begin; 12819 int end; 12820 int bit; 12821 12822 if (offloads == 0) 12823 return; 12824 12825 begin = __builtin_ctzll(offloads); 12826 end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads); 12827 12828 single_offload = 1ULL << begin; 12829 for (bit = begin; bit < end; bit++) { 12830 if (offloads & single_offload) 12831 printf(" %s", 12832 rte_eth_dev_tx_offload_name(single_offload)); 12833 single_offload <<= 1; 12834 } 12835 } 12836 12837 static void 12838 cmd_tx_offload_get_capa_parsed( 12839 void *parsed_result, 12840 __rte_unused struct cmdline *cl, 12841 __rte_unused void *data) 12842 { 12843 struct cmd_tx_offload_get_capa_result *res = parsed_result; 12844 struct rte_eth_dev_info dev_info; 12845 portid_t port_id = res->port_id; 12846 uint64_t queue_offloads; 12847 uint64_t port_offloads; 12848 int ret; 12849 12850 ret = eth_dev_info_get_print_err(port_id, &dev_info); 12851 if (ret != 0) 12852 return; 12853 12854 queue_offloads = dev_info.tx_queue_offload_capa; 12855 port_offloads = dev_info.tx_offload_capa ^ queue_offloads; 12856 12857 printf("Tx Offloading Capabilities of port %d :\n", port_id); 12858 printf(" Per Queue :"); 12859 print_tx_offloads(queue_offloads); 12860 12861 printf("\n"); 12862 printf(" Per Port :"); 12863 print_tx_offloads(port_offloads); 12864 printf("\n\n"); 12865 } 12866 12867 static cmdline_parse_inst_t cmd_tx_offload_get_capa = { 12868 .f = cmd_tx_offload_get_capa_parsed, 12869 .data = NULL, 12870 .help_str = "show port <port_id> tx_offload capabilities", 12871 .tokens = { 12872 (void *)&cmd_tx_offload_get_capa_show, 12873 (void *)&cmd_tx_offload_get_capa_port, 12874 (void *)&cmd_tx_offload_get_capa_port_id, 12875 (void *)&cmd_tx_offload_get_capa_tx_offload, 12876 (void *)&cmd_tx_offload_get_capa_capabilities, 12877 NULL, 12878 } 12879 }; 12880 12881 /* Get Tx offloads configuration */ 12882 struct cmd_tx_offload_get_configuration_result { 12883 cmdline_fixed_string_t show; 12884 cmdline_fixed_string_t port; 12885 portid_t port_id; 12886 cmdline_fixed_string_t tx_offload; 12887 cmdline_fixed_string_t configuration; 12888 }; 12889 12890 static cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show = 12891 TOKEN_STRING_INITIALIZER 12892 (struct cmd_tx_offload_get_configuration_result, 12893 show, "show"); 12894 static cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port = 12895 TOKEN_STRING_INITIALIZER 12896 (struct cmd_tx_offload_get_configuration_result, 12897 port, "port"); 12898 static cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id = 12899 TOKEN_NUM_INITIALIZER 12900 (struct cmd_tx_offload_get_configuration_result, 12901 port_id, RTE_UINT16); 12902 static cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload = 12903 TOKEN_STRING_INITIALIZER 12904 (struct cmd_tx_offload_get_configuration_result, 12905 tx_offload, "tx_offload"); 12906 static cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration = 12907 TOKEN_STRING_INITIALIZER 12908 (struct cmd_tx_offload_get_configuration_result, 12909 configuration, "configuration"); 12910 12911 static void 12912 cmd_tx_offload_get_configuration_parsed( 12913 void *parsed_result, 12914 __rte_unused struct cmdline *cl, 12915 __rte_unused void *data) 12916 { 12917 struct cmd_tx_offload_get_configuration_result *res = parsed_result; 12918 struct rte_eth_dev_info dev_info; 12919 portid_t port_id = res->port_id; 12920 struct rte_port *port = &ports[port_id]; 12921 struct rte_eth_conf dev_conf; 12922 uint64_t port_offloads; 12923 uint64_t queue_offloads; 12924 uint16_t nb_tx_queues; 12925 int q; 12926 int ret; 12927 12928 printf("Tx Offloading Configuration of port %d :\n", port_id); 12929 12930 ret = eth_dev_conf_get_print_err(port_id, &dev_conf); 12931 if (ret != 0) 12932 return; 12933 12934 port_offloads = dev_conf.txmode.offloads; 12935 printf(" Port :"); 12936 print_tx_offloads(port_offloads); 12937 printf("\n"); 12938 12939 ret = eth_dev_info_get_print_err(port_id, &dev_info); 12940 if (ret != 0) 12941 return; 12942 12943 nb_tx_queues = dev_info.nb_tx_queues; 12944 for (q = 0; q < nb_tx_queues; q++) { 12945 queue_offloads = port->txq[q].conf.offloads; 12946 printf(" Queue[%2d] :", q); 12947 print_tx_offloads(queue_offloads); 12948 printf("\n"); 12949 } 12950 printf("\n"); 12951 } 12952 12953 static cmdline_parse_inst_t cmd_tx_offload_get_configuration = { 12954 .f = cmd_tx_offload_get_configuration_parsed, 12955 .data = NULL, 12956 .help_str = "show port <port_id> tx_offload configuration", 12957 .tokens = { 12958 (void *)&cmd_tx_offload_get_configuration_show, 12959 (void *)&cmd_tx_offload_get_configuration_port, 12960 (void *)&cmd_tx_offload_get_configuration_port_id, 12961 (void *)&cmd_tx_offload_get_configuration_tx_offload, 12962 (void *)&cmd_tx_offload_get_configuration_configuration, 12963 NULL, 12964 } 12965 }; 12966 12967 /* Enable/Disable a per port offloading */ 12968 struct cmd_config_per_port_tx_offload_result { 12969 cmdline_fixed_string_t port; 12970 cmdline_fixed_string_t config; 12971 portid_t port_id; 12972 cmdline_fixed_string_t tx_offload; 12973 cmdline_fixed_string_t offload; 12974 cmdline_fixed_string_t on_off; 12975 }; 12976 12977 static cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port = 12978 TOKEN_STRING_INITIALIZER 12979 (struct cmd_config_per_port_tx_offload_result, 12980 port, "port"); 12981 static cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config = 12982 TOKEN_STRING_INITIALIZER 12983 (struct cmd_config_per_port_tx_offload_result, 12984 config, "config"); 12985 static cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id = 12986 TOKEN_NUM_INITIALIZER 12987 (struct cmd_config_per_port_tx_offload_result, 12988 port_id, RTE_UINT16); 12989 static cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload = 12990 TOKEN_STRING_INITIALIZER 12991 (struct cmd_config_per_port_tx_offload_result, 12992 tx_offload, "tx_offload"); 12993 static cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload = 12994 TOKEN_STRING_INITIALIZER 12995 (struct cmd_config_per_port_tx_offload_result, 12996 offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#" 12997 "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#" 12998 "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#" 12999 "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#" 13000 "mt_lockfree#multi_segs#mbuf_fast_free#security#" 13001 "send_on_timestamp"); 13002 static cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off = 13003 TOKEN_STRING_INITIALIZER 13004 (struct cmd_config_per_port_tx_offload_result, 13005 on_off, "on#off"); 13006 13007 static uint64_t 13008 search_tx_offload(const char *name) 13009 { 13010 uint64_t single_offload; 13011 const char *single_name; 13012 int found = 0; 13013 unsigned int bit; 13014 13015 single_offload = 1; 13016 for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) { 13017 single_name = rte_eth_dev_tx_offload_name(single_offload); 13018 if (single_name == NULL) 13019 break; 13020 if (!strcasecmp(single_name, name)) { 13021 found = 1; 13022 break; 13023 } else if (!strcasecmp(single_name, "UNKNOWN")) 13024 break; 13025 single_offload <<= 1; 13026 } 13027 13028 if (found) 13029 return single_offload; 13030 13031 return 0; 13032 } 13033 13034 static void 13035 cmd_config_per_port_tx_offload_parsed(void *parsed_result, 13036 __rte_unused struct cmdline *cl, 13037 __rte_unused void *data) 13038 { 13039 struct cmd_config_per_port_tx_offload_result *res = parsed_result; 13040 portid_t port_id = res->port_id; 13041 struct rte_eth_dev_info dev_info; 13042 struct rte_port *port = &ports[port_id]; 13043 uint64_t single_offload; 13044 uint16_t nb_tx_queues; 13045 int q; 13046 int ret; 13047 13048 if (port->port_status != RTE_PORT_STOPPED) { 13049 fprintf(stderr, 13050 "Error: Can't config offload when Port %d is not stopped\n", 13051 port_id); 13052 return; 13053 } 13054 13055 single_offload = search_tx_offload(res->offload); 13056 if (single_offload == 0) { 13057 fprintf(stderr, "Unknown offload name: %s\n", res->offload); 13058 return; 13059 } 13060 13061 ret = eth_dev_info_get_print_err(port_id, &dev_info); 13062 if (ret != 0) 13063 return; 13064 13065 nb_tx_queues = dev_info.nb_tx_queues; 13066 if (!strcmp(res->on_off, "on")) { 13067 port->dev_conf.txmode.offloads |= single_offload; 13068 for (q = 0; q < nb_tx_queues; q++) 13069 port->txq[q].conf.offloads |= single_offload; 13070 } else { 13071 port->dev_conf.txmode.offloads &= ~single_offload; 13072 for (q = 0; q < nb_tx_queues; q++) 13073 port->txq[q].conf.offloads &= ~single_offload; 13074 } 13075 13076 cmd_reconfig_device_queue(port_id, 1, 1); 13077 } 13078 13079 static cmdline_parse_inst_t cmd_config_per_port_tx_offload = { 13080 .f = cmd_config_per_port_tx_offload_parsed, 13081 .data = NULL, 13082 .help_str = "port config <port_id> tx_offload " 13083 "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|" 13084 "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|" 13085 "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|" 13086 "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|" 13087 "mt_lockfree|multi_segs|mbuf_fast_free|security|" 13088 "send_on_timestamp on|off", 13089 .tokens = { 13090 (void *)&cmd_config_per_port_tx_offload_result_port, 13091 (void *)&cmd_config_per_port_tx_offload_result_config, 13092 (void *)&cmd_config_per_port_tx_offload_result_port_id, 13093 (void *)&cmd_config_per_port_tx_offload_result_tx_offload, 13094 (void *)&cmd_config_per_port_tx_offload_result_offload, 13095 (void *)&cmd_config_per_port_tx_offload_result_on_off, 13096 NULL, 13097 } 13098 }; 13099 13100 /* Enable/Disable a per queue offloading */ 13101 struct cmd_config_per_queue_tx_offload_result { 13102 cmdline_fixed_string_t port; 13103 portid_t port_id; 13104 cmdline_fixed_string_t txq; 13105 uint16_t queue_id; 13106 cmdline_fixed_string_t tx_offload; 13107 cmdline_fixed_string_t offload; 13108 cmdline_fixed_string_t on_off; 13109 }; 13110 13111 static cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port = 13112 TOKEN_STRING_INITIALIZER 13113 (struct cmd_config_per_queue_tx_offload_result, 13114 port, "port"); 13115 static cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id = 13116 TOKEN_NUM_INITIALIZER 13117 (struct cmd_config_per_queue_tx_offload_result, 13118 port_id, RTE_UINT16); 13119 static cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq = 13120 TOKEN_STRING_INITIALIZER 13121 (struct cmd_config_per_queue_tx_offload_result, 13122 txq, "txq"); 13123 static cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id = 13124 TOKEN_NUM_INITIALIZER 13125 (struct cmd_config_per_queue_tx_offload_result, 13126 queue_id, RTE_UINT16); 13127 static cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload = 13128 TOKEN_STRING_INITIALIZER 13129 (struct cmd_config_per_queue_tx_offload_result, 13130 tx_offload, "tx_offload"); 13131 static cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload = 13132 TOKEN_STRING_INITIALIZER 13133 (struct cmd_config_per_queue_tx_offload_result, 13134 offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#" 13135 "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#" 13136 "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#" 13137 "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#" 13138 "mt_lockfree#multi_segs#mbuf_fast_free#security"); 13139 static cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off = 13140 TOKEN_STRING_INITIALIZER 13141 (struct cmd_config_per_queue_tx_offload_result, 13142 on_off, "on#off"); 13143 13144 static void 13145 cmd_config_per_queue_tx_offload_parsed(void *parsed_result, 13146 __rte_unused struct cmdline *cl, 13147 __rte_unused void *data) 13148 { 13149 struct cmd_config_per_queue_tx_offload_result *res = parsed_result; 13150 struct rte_eth_dev_info dev_info; 13151 portid_t port_id = res->port_id; 13152 uint16_t queue_id = res->queue_id; 13153 struct rte_port *port = &ports[port_id]; 13154 uint64_t single_offload; 13155 int ret; 13156 13157 if (port->port_status != RTE_PORT_STOPPED) { 13158 fprintf(stderr, 13159 "Error: Can't config offload when Port %d is not stopped\n", 13160 port_id); 13161 return; 13162 } 13163 13164 ret = eth_dev_info_get_print_err(port_id, &dev_info); 13165 if (ret != 0) 13166 return; 13167 13168 if (queue_id >= dev_info.nb_tx_queues) { 13169 fprintf(stderr, 13170 "Error: input queue_id should be 0 ... %d\n", 13171 dev_info.nb_tx_queues - 1); 13172 return; 13173 } 13174 13175 single_offload = search_tx_offload(res->offload); 13176 if (single_offload == 0) { 13177 fprintf(stderr, "Unknown offload name: %s\n", res->offload); 13178 return; 13179 } 13180 13181 if (!strcmp(res->on_off, "on")) 13182 port->txq[queue_id].conf.offloads |= single_offload; 13183 else 13184 port->txq[queue_id].conf.offloads &= ~single_offload; 13185 13186 cmd_reconfig_device_queue(port_id, 1, 1); 13187 } 13188 13189 static cmdline_parse_inst_t cmd_config_per_queue_tx_offload = { 13190 .f = cmd_config_per_queue_tx_offload_parsed, 13191 .data = NULL, 13192 .help_str = "port <port_id> txq <queue_id> tx_offload " 13193 "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|" 13194 "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|" 13195 "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|" 13196 "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|" 13197 "mt_lockfree|multi_segs|mbuf_fast_free|security " 13198 "on|off", 13199 .tokens = { 13200 (void *)&cmd_config_per_queue_tx_offload_result_port, 13201 (void *)&cmd_config_per_queue_tx_offload_result_port_id, 13202 (void *)&cmd_config_per_queue_tx_offload_result_txq, 13203 (void *)&cmd_config_per_queue_tx_offload_result_queue_id, 13204 (void *)&cmd_config_per_queue_tx_offload_result_txoffload, 13205 (void *)&cmd_config_per_queue_tx_offload_result_offload, 13206 (void *)&cmd_config_per_queue_tx_offload_result_on_off, 13207 NULL, 13208 } 13209 }; 13210 13211 /* *** configure tx_metadata for specific port *** */ 13212 struct cmd_config_tx_metadata_specific_result { 13213 cmdline_fixed_string_t port; 13214 cmdline_fixed_string_t keyword; 13215 uint16_t port_id; 13216 cmdline_fixed_string_t item; 13217 uint32_t value; 13218 }; 13219 13220 static void 13221 cmd_config_tx_metadata_specific_parsed(void *parsed_result, 13222 __rte_unused struct cmdline *cl, 13223 __rte_unused void *data) 13224 { 13225 struct cmd_config_tx_metadata_specific_result *res = parsed_result; 13226 13227 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 13228 return; 13229 ports[res->port_id].tx_metadata = res->value; 13230 /* Add/remove callback to insert valid metadata in every Tx packet. */ 13231 if (ports[res->port_id].tx_metadata) 13232 add_tx_md_callback(res->port_id); 13233 else 13234 remove_tx_md_callback(res->port_id); 13235 rte_flow_dynf_metadata_register(); 13236 } 13237 13238 static cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port = 13239 TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result, 13240 port, "port"); 13241 static cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword = 13242 TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result, 13243 keyword, "config"); 13244 static cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id = 13245 TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result, 13246 port_id, RTE_UINT16); 13247 static cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item = 13248 TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result, 13249 item, "tx_metadata"); 13250 static cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value = 13251 TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result, 13252 value, RTE_UINT32); 13253 13254 static cmdline_parse_inst_t cmd_config_tx_metadata_specific = { 13255 .f = cmd_config_tx_metadata_specific_parsed, 13256 .data = NULL, 13257 .help_str = "port config <port_id> tx_metadata <value>", 13258 .tokens = { 13259 (void *)&cmd_config_tx_metadata_specific_port, 13260 (void *)&cmd_config_tx_metadata_specific_keyword, 13261 (void *)&cmd_config_tx_metadata_specific_id, 13262 (void *)&cmd_config_tx_metadata_specific_item, 13263 (void *)&cmd_config_tx_metadata_specific_value, 13264 NULL, 13265 }, 13266 }; 13267 13268 /* *** set dynf *** */ 13269 struct cmd_config_tx_dynf_specific_result { 13270 cmdline_fixed_string_t port; 13271 cmdline_fixed_string_t keyword; 13272 uint16_t port_id; 13273 cmdline_fixed_string_t item; 13274 cmdline_fixed_string_t name; 13275 cmdline_fixed_string_t value; 13276 }; 13277 13278 static void 13279 cmd_config_dynf_specific_parsed(void *parsed_result, 13280 __rte_unused struct cmdline *cl, 13281 __rte_unused void *data) 13282 { 13283 struct cmd_config_tx_dynf_specific_result *res = parsed_result; 13284 struct rte_mbuf_dynflag desc_flag; 13285 int flag; 13286 uint64_t old_port_flags; 13287 13288 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 13289 return; 13290 flag = rte_mbuf_dynflag_lookup(res->name, NULL); 13291 if (flag <= 0) { 13292 if (strlcpy(desc_flag.name, res->name, 13293 RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) { 13294 fprintf(stderr, "Flag name too long\n"); 13295 return; 13296 } 13297 desc_flag.flags = 0; 13298 flag = rte_mbuf_dynflag_register(&desc_flag); 13299 if (flag < 0) { 13300 fprintf(stderr, "Can't register flag\n"); 13301 return; 13302 } 13303 strcpy(dynf_names[flag], desc_flag.name); 13304 } 13305 old_port_flags = ports[res->port_id].mbuf_dynf; 13306 if (!strcmp(res->value, "set")) { 13307 ports[res->port_id].mbuf_dynf |= 1UL << flag; 13308 if (old_port_flags == 0) 13309 add_tx_dynf_callback(res->port_id); 13310 } else { 13311 ports[res->port_id].mbuf_dynf &= ~(1UL << flag); 13312 if (ports[res->port_id].mbuf_dynf == 0) 13313 remove_tx_dynf_callback(res->port_id); 13314 } 13315 } 13316 13317 static cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port = 13318 TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result, 13319 keyword, "port"); 13320 static cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword = 13321 TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result, 13322 keyword, "config"); 13323 static cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id = 13324 TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result, 13325 port_id, RTE_UINT16); 13326 static cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item = 13327 TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result, 13328 item, "dynf"); 13329 static cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name = 13330 TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result, 13331 name, NULL); 13332 static cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value = 13333 TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result, 13334 value, "set#clear"); 13335 13336 static cmdline_parse_inst_t cmd_config_tx_dynf_specific = { 13337 .f = cmd_config_dynf_specific_parsed, 13338 .data = NULL, 13339 .help_str = "port config <port id> dynf <name> set|clear", 13340 .tokens = { 13341 (void *)&cmd_config_tx_dynf_specific_port, 13342 (void *)&cmd_config_tx_dynf_specific_keyword, 13343 (void *)&cmd_config_tx_dynf_specific_port_id, 13344 (void *)&cmd_config_tx_dynf_specific_item, 13345 (void *)&cmd_config_tx_dynf_specific_name, 13346 (void *)&cmd_config_tx_dynf_specific_value, 13347 NULL, 13348 }, 13349 }; 13350 13351 /* *** display tx_metadata per port configuration *** */ 13352 struct cmd_show_tx_metadata_result { 13353 cmdline_fixed_string_t cmd_show; 13354 cmdline_fixed_string_t cmd_port; 13355 cmdline_fixed_string_t cmd_keyword; 13356 portid_t cmd_pid; 13357 }; 13358 13359 static void 13360 cmd_show_tx_metadata_parsed(void *parsed_result, 13361 __rte_unused struct cmdline *cl, 13362 __rte_unused void *data) 13363 { 13364 struct cmd_show_tx_metadata_result *res = parsed_result; 13365 13366 if (!rte_eth_dev_is_valid_port(res->cmd_pid)) { 13367 fprintf(stderr, "invalid port id %u\n", res->cmd_pid); 13368 return; 13369 } 13370 if (!strcmp(res->cmd_keyword, "tx_metadata")) { 13371 printf("Port %u tx_metadata: %u\n", res->cmd_pid, 13372 ports[res->cmd_pid].tx_metadata); 13373 } 13374 } 13375 13376 static cmdline_parse_token_string_t cmd_show_tx_metadata_show = 13377 TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result, 13378 cmd_show, "show"); 13379 static cmdline_parse_token_string_t cmd_show_tx_metadata_port = 13380 TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result, 13381 cmd_port, "port"); 13382 static cmdline_parse_token_num_t cmd_show_tx_metadata_pid = 13383 TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result, 13384 cmd_pid, RTE_UINT16); 13385 static cmdline_parse_token_string_t cmd_show_tx_metadata_keyword = 13386 TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result, 13387 cmd_keyword, "tx_metadata"); 13388 13389 static cmdline_parse_inst_t cmd_show_tx_metadata = { 13390 .f = cmd_show_tx_metadata_parsed, 13391 .data = NULL, 13392 .help_str = "show port <port_id> tx_metadata", 13393 .tokens = { 13394 (void *)&cmd_show_tx_metadata_show, 13395 (void *)&cmd_show_tx_metadata_port, 13396 (void *)&cmd_show_tx_metadata_pid, 13397 (void *)&cmd_show_tx_metadata_keyword, 13398 NULL, 13399 }, 13400 }; 13401 13402 /* *** show fec capability per port configuration *** */ 13403 struct cmd_show_fec_capability_result { 13404 cmdline_fixed_string_t cmd_show; 13405 cmdline_fixed_string_t cmd_port; 13406 cmdline_fixed_string_t cmd_fec; 13407 cmdline_fixed_string_t cmd_keyword; 13408 portid_t cmd_pid; 13409 }; 13410 13411 static void 13412 cmd_show_fec_capability_parsed(void *parsed_result, 13413 __rte_unused struct cmdline *cl, 13414 __rte_unused void *data) 13415 { 13416 struct cmd_show_fec_capability_result *res = parsed_result; 13417 struct rte_eth_fec_capa *speed_fec_capa; 13418 unsigned int num; 13419 int ret; 13420 13421 if (!rte_eth_dev_is_valid_port(res->cmd_pid)) { 13422 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid); 13423 return; 13424 } 13425 13426 ret = rte_eth_fec_get_capability(res->cmd_pid, NULL, 0); 13427 if (ret == -ENOTSUP) { 13428 fprintf(stderr, "Function not implemented\n"); 13429 return; 13430 } else if (ret < 0) { 13431 fprintf(stderr, "Get FEC capability failed: %d\n", ret); 13432 return; 13433 } 13434 13435 num = (unsigned int)ret; 13436 speed_fec_capa = calloc(num, sizeof(*speed_fec_capa)); 13437 if (speed_fec_capa == NULL) { 13438 fprintf(stderr, "Failed to alloc FEC capability buffer\n"); 13439 return; 13440 } 13441 13442 ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num); 13443 if (ret < 0) { 13444 fprintf(stderr, "Error getting FEC capability: %d\n", ret); 13445 goto out; 13446 } 13447 13448 show_fec_capability(num, speed_fec_capa); 13449 out: 13450 free(speed_fec_capa); 13451 } 13452 13453 static cmdline_parse_token_string_t cmd_show_fec_capability_show = 13454 TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result, 13455 cmd_show, "show"); 13456 static cmdline_parse_token_string_t cmd_show_fec_capability_port = 13457 TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result, 13458 cmd_port, "port"); 13459 static cmdline_parse_token_num_t cmd_show_fec_capability_pid = 13460 TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result, 13461 cmd_pid, RTE_UINT16); 13462 static cmdline_parse_token_string_t cmd_show_fec_capability_fec = 13463 TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result, 13464 cmd_fec, "fec"); 13465 static cmdline_parse_token_string_t cmd_show_fec_capability_keyword = 13466 TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result, 13467 cmd_keyword, "capabilities"); 13468 13469 static cmdline_parse_inst_t cmd_show_capability = { 13470 .f = cmd_show_fec_capability_parsed, 13471 .data = NULL, 13472 .help_str = "show port <port_id> fec capabilities", 13473 .tokens = { 13474 (void *)&cmd_show_fec_capability_show, 13475 (void *)&cmd_show_fec_capability_port, 13476 (void *)&cmd_show_fec_capability_pid, 13477 (void *)&cmd_show_fec_capability_fec, 13478 (void *)&cmd_show_fec_capability_keyword, 13479 NULL, 13480 }, 13481 }; 13482 13483 /* *** show fec mode per port configuration *** */ 13484 struct cmd_show_fec_metadata_result { 13485 cmdline_fixed_string_t cmd_show; 13486 cmdline_fixed_string_t cmd_port; 13487 cmdline_fixed_string_t cmd_keyword; 13488 portid_t cmd_pid; 13489 }; 13490 13491 static void 13492 cmd_show_fec_mode_parsed(void *parsed_result, 13493 __rte_unused struct cmdline *cl, 13494 __rte_unused void *data) 13495 { 13496 #define FEC_NAME_SIZE 16 13497 struct cmd_show_fec_metadata_result *res = parsed_result; 13498 uint32_t mode; 13499 char buf[FEC_NAME_SIZE]; 13500 int ret; 13501 13502 if (!rte_eth_dev_is_valid_port(res->cmd_pid)) { 13503 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid); 13504 return; 13505 } 13506 ret = rte_eth_fec_get(res->cmd_pid, &mode); 13507 if (ret == -ENOTSUP) { 13508 fprintf(stderr, "Function not implemented\n"); 13509 return; 13510 } else if (ret < 0) { 13511 fprintf(stderr, "Get FEC mode failed\n"); 13512 return; 13513 } 13514 13515 switch (mode) { 13516 case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC): 13517 strlcpy(buf, "off", sizeof(buf)); 13518 break; 13519 case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO): 13520 strlcpy(buf, "auto", sizeof(buf)); 13521 break; 13522 case RTE_ETH_FEC_MODE_CAPA_MASK(BASER): 13523 strlcpy(buf, "baser", sizeof(buf)); 13524 break; 13525 case RTE_ETH_FEC_MODE_CAPA_MASK(RS): 13526 strlcpy(buf, "rs", sizeof(buf)); 13527 break; 13528 default: 13529 return; 13530 } 13531 13532 printf("%s\n", buf); 13533 } 13534 13535 static cmdline_parse_token_string_t cmd_show_fec_mode_show = 13536 TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result, 13537 cmd_show, "show"); 13538 static cmdline_parse_token_string_t cmd_show_fec_mode_port = 13539 TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result, 13540 cmd_port, "port"); 13541 static cmdline_parse_token_num_t cmd_show_fec_mode_pid = 13542 TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result, 13543 cmd_pid, RTE_UINT16); 13544 static cmdline_parse_token_string_t cmd_show_fec_mode_keyword = 13545 TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result, 13546 cmd_keyword, "fec_mode"); 13547 13548 static cmdline_parse_inst_t cmd_show_fec_mode = { 13549 .f = cmd_show_fec_mode_parsed, 13550 .data = NULL, 13551 .help_str = "show port <port_id> fec_mode", 13552 .tokens = { 13553 (void *)&cmd_show_fec_mode_show, 13554 (void *)&cmd_show_fec_mode_port, 13555 (void *)&cmd_show_fec_mode_pid, 13556 (void *)&cmd_show_fec_mode_keyword, 13557 NULL, 13558 }, 13559 }; 13560 13561 /* *** set fec mode per port configuration *** */ 13562 struct cmd_set_port_fec_mode { 13563 cmdline_fixed_string_t set; 13564 cmdline_fixed_string_t port; 13565 portid_t port_id; 13566 cmdline_fixed_string_t fec_mode; 13567 cmdline_fixed_string_t fec_value; 13568 }; 13569 13570 /* Common CLI fields for set fec mode */ 13571 static cmdline_parse_token_string_t cmd_set_port_fec_mode_set = 13572 TOKEN_STRING_INITIALIZER 13573 (struct cmd_set_port_fec_mode, 13574 set, "set"); 13575 static cmdline_parse_token_string_t cmd_set_port_fec_mode_port = 13576 TOKEN_STRING_INITIALIZER 13577 (struct cmd_set_port_fec_mode, 13578 port, "port"); 13579 static cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id = 13580 TOKEN_NUM_INITIALIZER 13581 (struct cmd_set_port_fec_mode, 13582 port_id, RTE_UINT16); 13583 static cmdline_parse_token_string_t cmd_set_port_fec_mode_str = 13584 TOKEN_STRING_INITIALIZER 13585 (struct cmd_set_port_fec_mode, 13586 fec_mode, "fec_mode"); 13587 static cmdline_parse_token_string_t cmd_set_port_fec_mode_value = 13588 TOKEN_STRING_INITIALIZER 13589 (struct cmd_set_port_fec_mode, 13590 fec_value, NULL); 13591 13592 static void 13593 cmd_set_port_fec_mode_parsed( 13594 void *parsed_result, 13595 __rte_unused struct cmdline *cl, 13596 __rte_unused void *data) 13597 { 13598 struct cmd_set_port_fec_mode *res = parsed_result; 13599 uint16_t port_id = res->port_id; 13600 uint32_t fec_capa; 13601 int ret; 13602 13603 ret = parse_fec_mode(res->fec_value, &fec_capa); 13604 if (ret < 0) { 13605 fprintf(stderr, "Unknown fec mode: %s for port %d\n", 13606 res->fec_value, port_id); 13607 return; 13608 } 13609 13610 ret = rte_eth_fec_set(port_id, fec_capa); 13611 if (ret == -ENOTSUP) { 13612 fprintf(stderr, "Function not implemented\n"); 13613 return; 13614 } else if (ret < 0) { 13615 fprintf(stderr, "Set FEC mode failed\n"); 13616 return; 13617 } 13618 } 13619 13620 static cmdline_parse_inst_t cmd_set_fec_mode = { 13621 .f = cmd_set_port_fec_mode_parsed, 13622 .data = NULL, 13623 .help_str = "set port <port_id> fec_mode auto|off|rs|baser", 13624 .tokens = { 13625 (void *)&cmd_set_port_fec_mode_set, 13626 (void *)&cmd_set_port_fec_mode_port, 13627 (void *)&cmd_set_port_fec_mode_port_id, 13628 (void *)&cmd_set_port_fec_mode_str, 13629 (void *)&cmd_set_port_fec_mode_value, 13630 NULL, 13631 }, 13632 }; 13633 13634 /* *** set available descriptors threshold for an RxQ of a port *** */ 13635 struct cmd_set_rxq_avail_thresh_result { 13636 cmdline_fixed_string_t set; 13637 cmdline_fixed_string_t port; 13638 uint16_t port_num; 13639 cmdline_fixed_string_t rxq; 13640 uint16_t rxq_num; 13641 cmdline_fixed_string_t avail_thresh; 13642 uint8_t avail_thresh_num; 13643 }; 13644 13645 static void cmd_set_rxq_avail_thresh_parsed(void *parsed_result, 13646 __rte_unused struct cmdline *cl, 13647 __rte_unused void *data) 13648 { 13649 struct cmd_set_rxq_avail_thresh_result *res = parsed_result; 13650 int ret = 0; 13651 13652 if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0) 13653 && (strcmp(res->rxq, "rxq") == 0) 13654 && (strcmp(res->avail_thresh, "avail_thresh") == 0)) 13655 ret = set_rxq_avail_thresh(res->port_num, res->rxq_num, 13656 res->avail_thresh_num); 13657 if (ret < 0) 13658 printf("rxq_avail_thresh_cmd error: (%s)\n", strerror(-ret)); 13659 13660 } 13661 13662 static cmdline_parse_token_string_t cmd_set_rxq_avail_thresh_set = 13663 TOKEN_STRING_INITIALIZER(struct cmd_set_rxq_avail_thresh_result, 13664 set, "set"); 13665 static cmdline_parse_token_string_t cmd_set_rxq_avail_thresh_port = 13666 TOKEN_STRING_INITIALIZER(struct cmd_set_rxq_avail_thresh_result, 13667 port, "port"); 13668 static cmdline_parse_token_num_t cmd_set_rxq_avail_thresh_portnum = 13669 TOKEN_NUM_INITIALIZER(struct cmd_set_rxq_avail_thresh_result, 13670 port_num, RTE_UINT16); 13671 static cmdline_parse_token_string_t cmd_set_rxq_avail_thresh_rxq = 13672 TOKEN_STRING_INITIALIZER(struct cmd_set_rxq_avail_thresh_result, 13673 rxq, "rxq"); 13674 static cmdline_parse_token_num_t cmd_set_rxq_avail_thresh_rxqnum = 13675 TOKEN_NUM_INITIALIZER(struct cmd_set_rxq_avail_thresh_result, 13676 rxq_num, RTE_UINT16); 13677 static cmdline_parse_token_string_t cmd_set_rxq_avail_thresh_avail_thresh = 13678 TOKEN_STRING_INITIALIZER(struct cmd_set_rxq_avail_thresh_result, 13679 avail_thresh, "avail_thresh"); 13680 static cmdline_parse_token_num_t cmd_set_rxq_avail_thresh_avail_threshnum = 13681 TOKEN_NUM_INITIALIZER(struct cmd_set_rxq_avail_thresh_result, 13682 avail_thresh_num, RTE_UINT8); 13683 13684 static cmdline_parse_inst_t cmd_set_rxq_avail_thresh = { 13685 .f = cmd_set_rxq_avail_thresh_parsed, 13686 .data = (void *)0, 13687 .help_str = 13688 "set port <port_id> rxq <queue_id> avail_thresh <0..99>: " 13689 "Set available descriptors threshold for Rx queue", 13690 .tokens = { 13691 (void *)&cmd_set_rxq_avail_thresh_set, 13692 (void *)&cmd_set_rxq_avail_thresh_port, 13693 (void *)&cmd_set_rxq_avail_thresh_portnum, 13694 (void *)&cmd_set_rxq_avail_thresh_rxq, 13695 (void *)&cmd_set_rxq_avail_thresh_rxqnum, 13696 (void *)&cmd_set_rxq_avail_thresh_avail_thresh, 13697 (void *)&cmd_set_rxq_avail_thresh_avail_threshnum, 13698 NULL, 13699 }, 13700 }; 13701 13702 /* show port supported ptypes */ 13703 13704 /* Common result structure for show port ptypes */ 13705 struct cmd_show_port_supported_ptypes_result { 13706 cmdline_fixed_string_t show; 13707 cmdline_fixed_string_t port; 13708 portid_t port_id; 13709 cmdline_fixed_string_t ptypes; 13710 }; 13711 13712 /* Common CLI fields for show port ptypes */ 13713 static cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show = 13714 TOKEN_STRING_INITIALIZER 13715 (struct cmd_show_port_supported_ptypes_result, 13716 show, "show"); 13717 static cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port = 13718 TOKEN_STRING_INITIALIZER 13719 (struct cmd_show_port_supported_ptypes_result, 13720 port, "port"); 13721 static cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id = 13722 TOKEN_NUM_INITIALIZER 13723 (struct cmd_show_port_supported_ptypes_result, 13724 port_id, RTE_UINT16); 13725 static cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes = 13726 TOKEN_STRING_INITIALIZER 13727 (struct cmd_show_port_supported_ptypes_result, 13728 ptypes, "ptypes"); 13729 13730 static void 13731 cmd_show_port_supported_ptypes_parsed( 13732 void *parsed_result, 13733 __rte_unused struct cmdline *cl, 13734 __rte_unused void *data) 13735 { 13736 #define RSVD_PTYPE_MASK 0xf0000000 13737 #define MAX_PTYPES_PER_LAYER 16 13738 #define LTYPE_NAMESIZE 32 13739 #define PTYPE_NAMESIZE 256 13740 struct cmd_show_port_supported_ptypes_result *res = parsed_result; 13741 char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE]; 13742 uint32_t ptype_mask = RTE_PTYPE_L2_MASK; 13743 uint32_t ptypes[MAX_PTYPES_PER_LAYER]; 13744 uint16_t port_id = res->port_id; 13745 int ret, i; 13746 13747 ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0); 13748 if (ret < 0) 13749 return; 13750 13751 while (ptype_mask != RSVD_PTYPE_MASK) { 13752 13753 switch (ptype_mask) { 13754 case RTE_PTYPE_L2_MASK: 13755 strlcpy(ltype, "L2", sizeof(ltype)); 13756 break; 13757 case RTE_PTYPE_L3_MASK: 13758 strlcpy(ltype, "L3", sizeof(ltype)); 13759 break; 13760 case RTE_PTYPE_L4_MASK: 13761 strlcpy(ltype, "L4", sizeof(ltype)); 13762 break; 13763 case RTE_PTYPE_TUNNEL_MASK: 13764 strlcpy(ltype, "Tunnel", sizeof(ltype)); 13765 break; 13766 case RTE_PTYPE_INNER_L2_MASK: 13767 strlcpy(ltype, "Inner L2", sizeof(ltype)); 13768 break; 13769 case RTE_PTYPE_INNER_L3_MASK: 13770 strlcpy(ltype, "Inner L3", sizeof(ltype)); 13771 break; 13772 case RTE_PTYPE_INNER_L4_MASK: 13773 strlcpy(ltype, "Inner L4", sizeof(ltype)); 13774 break; 13775 default: 13776 return; 13777 } 13778 13779 ret = rte_eth_dev_get_supported_ptypes(res->port_id, 13780 ptype_mask, ptypes, 13781 MAX_PTYPES_PER_LAYER); 13782 13783 if (ret > 0) 13784 printf("Supported %s ptypes:\n", ltype); 13785 else 13786 printf("%s ptypes unsupported\n", ltype); 13787 13788 for (i = 0; i < ret; ++i) { 13789 rte_get_ptype_name(ptypes[i], buf, sizeof(buf)); 13790 printf("%s\n", buf); 13791 } 13792 13793 ptype_mask <<= 4; 13794 } 13795 } 13796 13797 static cmdline_parse_inst_t cmd_show_port_supported_ptypes = { 13798 .f = cmd_show_port_supported_ptypes_parsed, 13799 .data = NULL, 13800 .help_str = "show port <port_id> ptypes", 13801 .tokens = { 13802 (void *)&cmd_show_port_supported_ptypes_show, 13803 (void *)&cmd_show_port_supported_ptypes_port, 13804 (void *)&cmd_show_port_supported_ptypes_port_id, 13805 (void *)&cmd_show_port_supported_ptypes_ptypes, 13806 NULL, 13807 }, 13808 }; 13809 13810 /* *** display rx/tx descriptor status *** */ 13811 struct cmd_show_rx_tx_desc_status_result { 13812 cmdline_fixed_string_t cmd_show; 13813 cmdline_fixed_string_t cmd_port; 13814 cmdline_fixed_string_t cmd_keyword; 13815 cmdline_fixed_string_t cmd_desc; 13816 cmdline_fixed_string_t cmd_status; 13817 portid_t cmd_pid; 13818 portid_t cmd_qid; 13819 portid_t cmd_did; 13820 }; 13821 13822 static void 13823 cmd_show_rx_tx_desc_status_parsed(void *parsed_result, 13824 __rte_unused struct cmdline *cl, 13825 __rte_unused void *data) 13826 { 13827 struct cmd_show_rx_tx_desc_status_result *res = parsed_result; 13828 int rc; 13829 13830 if (!rte_eth_dev_is_valid_port(res->cmd_pid)) { 13831 fprintf(stderr, "invalid port id %u\n", res->cmd_pid); 13832 return; 13833 } 13834 13835 if (!strcmp(res->cmd_keyword, "rxq")) { 13836 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid, 13837 res->cmd_did); 13838 if (rc < 0) { 13839 fprintf(stderr, 13840 "Invalid input: queue id = %d, desc id = %d\n", 13841 res->cmd_qid, res->cmd_did); 13842 return; 13843 } 13844 if (rc == RTE_ETH_RX_DESC_AVAIL) 13845 printf("Desc status = AVAILABLE\n"); 13846 else if (rc == RTE_ETH_RX_DESC_DONE) 13847 printf("Desc status = DONE\n"); 13848 else 13849 printf("Desc status = UNAVAILABLE\n"); 13850 } else if (!strcmp(res->cmd_keyword, "txq")) { 13851 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid, 13852 res->cmd_did); 13853 if (rc < 0) { 13854 fprintf(stderr, 13855 "Invalid input: queue id = %d, desc id = %d\n", 13856 res->cmd_qid, res->cmd_did); 13857 return; 13858 } 13859 if (rc == RTE_ETH_TX_DESC_FULL) 13860 printf("Desc status = FULL\n"); 13861 else if (rc == RTE_ETH_TX_DESC_DONE) 13862 printf("Desc status = DONE\n"); 13863 else 13864 printf("Desc status = UNAVAILABLE\n"); 13865 } 13866 } 13867 13868 static cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show = 13869 TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result, 13870 cmd_show, "show"); 13871 static cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port = 13872 TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result, 13873 cmd_port, "port"); 13874 static cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid = 13875 TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result, 13876 cmd_pid, RTE_UINT16); 13877 static cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword = 13878 TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result, 13879 cmd_keyword, "rxq#txq"); 13880 static cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid = 13881 TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result, 13882 cmd_qid, RTE_UINT16); 13883 static cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc = 13884 TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result, 13885 cmd_desc, "desc"); 13886 static cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did = 13887 TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result, 13888 cmd_did, RTE_UINT16); 13889 static cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status = 13890 TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result, 13891 cmd_status, "status"); 13892 static cmdline_parse_inst_t cmd_show_rx_tx_desc_status = { 13893 .f = cmd_show_rx_tx_desc_status_parsed, 13894 .data = NULL, 13895 .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> " 13896 "status", 13897 .tokens = { 13898 (void *)&cmd_show_rx_tx_desc_status_show, 13899 (void *)&cmd_show_rx_tx_desc_status_port, 13900 (void *)&cmd_show_rx_tx_desc_status_pid, 13901 (void *)&cmd_show_rx_tx_desc_status_keyword, 13902 (void *)&cmd_show_rx_tx_desc_status_qid, 13903 (void *)&cmd_show_rx_tx_desc_status_desc, 13904 (void *)&cmd_show_rx_tx_desc_status_did, 13905 (void *)&cmd_show_rx_tx_desc_status_status, 13906 NULL, 13907 }, 13908 }; 13909 13910 /* *** display rx queue desc used count *** */ 13911 struct cmd_show_rx_queue_desc_used_count_result { 13912 cmdline_fixed_string_t cmd_show; 13913 cmdline_fixed_string_t cmd_port; 13914 cmdline_fixed_string_t cmd_rxq; 13915 cmdline_fixed_string_t cmd_desc; 13916 cmdline_fixed_string_t cmd_used; 13917 cmdline_fixed_string_t cmd_count; 13918 portid_t cmd_pid; 13919 portid_t cmd_qid; 13920 }; 13921 13922 static void 13923 cmd_show_rx_queue_desc_used_count_parsed(void *parsed_result, 13924 __rte_unused struct cmdline *cl, 13925 __rte_unused void *data) 13926 { 13927 struct cmd_show_rx_queue_desc_used_count_result *res = parsed_result; 13928 int rc; 13929 13930 if (!rte_eth_dev_is_valid_port(res->cmd_pid)) { 13931 fprintf(stderr, "invalid port id %u\n", res->cmd_pid); 13932 return; 13933 } 13934 13935 rc = rte_eth_rx_queue_count(res->cmd_pid, res->cmd_qid); 13936 if (rc < 0) { 13937 fprintf(stderr, "Invalid queueid = %d\n", res->cmd_qid); 13938 return; 13939 } 13940 printf("Used desc count = %d\n", rc); 13941 } 13942 13943 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_show = 13944 TOKEN_STRING_INITIALIZER 13945 (struct cmd_show_rx_queue_desc_used_count_result, 13946 cmd_show, "show"); 13947 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_port = 13948 TOKEN_STRING_INITIALIZER 13949 (struct cmd_show_rx_queue_desc_used_count_result, 13950 cmd_port, "port"); 13951 static cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_pid = 13952 TOKEN_NUM_INITIALIZER 13953 (struct cmd_show_rx_queue_desc_used_count_result, 13954 cmd_pid, RTE_UINT16); 13955 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_rxq = 13956 TOKEN_STRING_INITIALIZER 13957 (struct cmd_show_rx_queue_desc_used_count_result, 13958 cmd_rxq, "rxq"); 13959 static cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_qid = 13960 TOKEN_NUM_INITIALIZER 13961 (struct cmd_show_rx_queue_desc_used_count_result, 13962 cmd_qid, RTE_UINT16); 13963 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_desc = 13964 TOKEN_STRING_INITIALIZER 13965 (struct cmd_show_rx_queue_desc_used_count_result, 13966 cmd_count, "desc"); 13967 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_used = 13968 TOKEN_STRING_INITIALIZER 13969 (struct cmd_show_rx_queue_desc_used_count_result, 13970 cmd_count, "used"); 13971 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_count = 13972 TOKEN_STRING_INITIALIZER 13973 (struct cmd_show_rx_queue_desc_used_count_result, 13974 cmd_count, "count"); 13975 static cmdline_parse_inst_t cmd_show_rx_queue_desc_used_count = { 13976 .f = cmd_show_rx_queue_desc_used_count_parsed, 13977 .data = NULL, 13978 .help_str = "show port <port_id> rxq <queue_id> desc used count", 13979 .tokens = { 13980 (void *)&cmd_show_rx_queue_desc_used_count_show, 13981 (void *)&cmd_show_rx_queue_desc_used_count_port, 13982 (void *)&cmd_show_rx_queue_desc_used_count_pid, 13983 (void *)&cmd_show_rx_queue_desc_used_count_rxq, 13984 (void *)&cmd_show_rx_queue_desc_used_count_qid, 13985 (void *)&cmd_show_rx_queue_desc_used_count_desc, 13986 (void *)&cmd_show_rx_queue_desc_used_count_used, 13987 (void *)&cmd_show_rx_queue_desc_used_count_count, 13988 NULL, 13989 }, 13990 }; 13991 13992 /* Common result structure for set port ptypes */ 13993 struct cmd_set_port_ptypes_result { 13994 cmdline_fixed_string_t set; 13995 cmdline_fixed_string_t port; 13996 portid_t port_id; 13997 cmdline_fixed_string_t ptype_mask; 13998 uint32_t mask; 13999 }; 14000 14001 /* Common CLI fields for set port ptypes */ 14002 static cmdline_parse_token_string_t cmd_set_port_ptypes_set = 14003 TOKEN_STRING_INITIALIZER 14004 (struct cmd_set_port_ptypes_result, 14005 set, "set"); 14006 static cmdline_parse_token_string_t cmd_set_port_ptypes_port = 14007 TOKEN_STRING_INITIALIZER 14008 (struct cmd_set_port_ptypes_result, 14009 port, "port"); 14010 static cmdline_parse_token_num_t cmd_set_port_ptypes_port_id = 14011 TOKEN_NUM_INITIALIZER 14012 (struct cmd_set_port_ptypes_result, 14013 port_id, RTE_UINT16); 14014 static cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str = 14015 TOKEN_STRING_INITIALIZER 14016 (struct cmd_set_port_ptypes_result, 14017 ptype_mask, "ptype_mask"); 14018 static cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 = 14019 TOKEN_NUM_INITIALIZER 14020 (struct cmd_set_port_ptypes_result, 14021 mask, RTE_UINT32); 14022 14023 static void 14024 cmd_set_port_ptypes_parsed( 14025 void *parsed_result, 14026 __rte_unused struct cmdline *cl, 14027 __rte_unused void *data) 14028 { 14029 struct cmd_set_port_ptypes_result *res = parsed_result; 14030 #define PTYPE_NAMESIZE 256 14031 char ptype_name[PTYPE_NAMESIZE]; 14032 uint16_t port_id = res->port_id; 14033 uint32_t ptype_mask = res->mask; 14034 int ret, i; 14035 14036 ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK, 14037 NULL, 0); 14038 if (ret <= 0) { 14039 fprintf(stderr, "Port %d doesn't support any ptypes.\n", 14040 port_id); 14041 return; 14042 } 14043 14044 uint32_t ptypes[ret]; 14045 14046 ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret); 14047 if (ret < 0) { 14048 fprintf(stderr, "Unable to set requested ptypes for Port %d\n", 14049 port_id); 14050 return; 14051 } 14052 14053 printf("Successfully set following ptypes for Port %d\n", port_id); 14054 for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) { 14055 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name)); 14056 printf("%s\n", ptype_name); 14057 } 14058 14059 clear_ptypes = false; 14060 } 14061 14062 static cmdline_parse_inst_t cmd_set_port_ptypes = { 14063 .f = cmd_set_port_ptypes_parsed, 14064 .data = NULL, 14065 .help_str = "set port <port_id> ptype_mask <mask>", 14066 .tokens = { 14067 (void *)&cmd_set_port_ptypes_set, 14068 (void *)&cmd_set_port_ptypes_port, 14069 (void *)&cmd_set_port_ptypes_port_id, 14070 (void *)&cmd_set_port_ptypes_mask_str, 14071 (void *)&cmd_set_port_ptypes_mask_u32, 14072 NULL, 14073 }, 14074 }; 14075 14076 /* *** display mac addresses added to a port *** */ 14077 struct cmd_showport_macs_result { 14078 cmdline_fixed_string_t cmd_show; 14079 cmdline_fixed_string_t cmd_port; 14080 cmdline_fixed_string_t cmd_keyword; 14081 portid_t cmd_pid; 14082 }; 14083 14084 static void 14085 cmd_showport_macs_parsed(void *parsed_result, 14086 __rte_unused struct cmdline *cl, 14087 __rte_unused void *data) 14088 { 14089 struct cmd_showport_macs_result *res = parsed_result; 14090 14091 if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN)) 14092 return; 14093 14094 if (!strcmp(res->cmd_keyword, "macs")) 14095 show_macs(res->cmd_pid); 14096 else if (!strcmp(res->cmd_keyword, "mcast_macs")) 14097 show_mcast_macs(res->cmd_pid); 14098 } 14099 14100 static cmdline_parse_token_string_t cmd_showport_macs_show = 14101 TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result, 14102 cmd_show, "show"); 14103 static cmdline_parse_token_string_t cmd_showport_macs_port = 14104 TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result, 14105 cmd_port, "port"); 14106 static cmdline_parse_token_num_t cmd_showport_macs_pid = 14107 TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result, 14108 cmd_pid, RTE_UINT16); 14109 static cmdline_parse_token_string_t cmd_showport_macs_keyword = 14110 TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result, 14111 cmd_keyword, "macs#mcast_macs"); 14112 14113 static cmdline_parse_inst_t cmd_showport_macs = { 14114 .f = cmd_showport_macs_parsed, 14115 .data = NULL, 14116 .help_str = "show port <port_id> macs|mcast_macs", 14117 .tokens = { 14118 (void *)&cmd_showport_macs_show, 14119 (void *)&cmd_showport_macs_port, 14120 (void *)&cmd_showport_macs_pid, 14121 (void *)&cmd_showport_macs_keyword, 14122 NULL, 14123 }, 14124 }; 14125 14126 /* *** show flow transfer proxy port ID for the given port *** */ 14127 struct cmd_show_port_flow_transfer_proxy_result { 14128 cmdline_fixed_string_t show; 14129 cmdline_fixed_string_t port; 14130 portid_t port_id; 14131 cmdline_fixed_string_t flow; 14132 cmdline_fixed_string_t transfer; 14133 cmdline_fixed_string_t proxy; 14134 }; 14135 14136 static cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_show = 14137 TOKEN_STRING_INITIALIZER 14138 (struct cmd_show_port_flow_transfer_proxy_result, 14139 show, "show"); 14140 static cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_port = 14141 TOKEN_STRING_INITIALIZER 14142 (struct cmd_show_port_flow_transfer_proxy_result, 14143 port, "port"); 14144 static cmdline_parse_token_num_t cmd_show_port_flow_transfer_proxy_port_id = 14145 TOKEN_NUM_INITIALIZER 14146 (struct cmd_show_port_flow_transfer_proxy_result, 14147 port_id, RTE_UINT16); 14148 static cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_flow = 14149 TOKEN_STRING_INITIALIZER 14150 (struct cmd_show_port_flow_transfer_proxy_result, 14151 flow, "flow"); 14152 static cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_transfer = 14153 TOKEN_STRING_INITIALIZER 14154 (struct cmd_show_port_flow_transfer_proxy_result, 14155 transfer, "transfer"); 14156 static cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_proxy = 14157 TOKEN_STRING_INITIALIZER 14158 (struct cmd_show_port_flow_transfer_proxy_result, 14159 proxy, "proxy"); 14160 14161 static void 14162 cmd_show_port_flow_transfer_proxy_parsed(void *parsed_result, 14163 __rte_unused struct cmdline *cl, 14164 __rte_unused void *data) 14165 { 14166 struct cmd_show_port_flow_transfer_proxy_result *res = parsed_result; 14167 portid_t proxy_port_id; 14168 int ret; 14169 14170 printf("\n"); 14171 14172 ret = rte_flow_pick_transfer_proxy(res->port_id, &proxy_port_id, NULL); 14173 if (ret != 0) { 14174 fprintf(stderr, "Failed to pick transfer proxy: %s\n", 14175 rte_strerror(-ret)); 14176 return; 14177 } 14178 14179 printf("Transfer proxy port ID: %u\n\n", proxy_port_id); 14180 } 14181 14182 static cmdline_parse_inst_t cmd_show_port_flow_transfer_proxy = { 14183 .f = cmd_show_port_flow_transfer_proxy_parsed, 14184 .data = NULL, 14185 .help_str = "show port <port_id> flow transfer proxy", 14186 .tokens = { 14187 (void *)&cmd_show_port_flow_transfer_proxy_show, 14188 (void *)&cmd_show_port_flow_transfer_proxy_port, 14189 (void *)&cmd_show_port_flow_transfer_proxy_port_id, 14190 (void *)&cmd_show_port_flow_transfer_proxy_flow, 14191 (void *)&cmd_show_port_flow_transfer_proxy_transfer, 14192 (void *)&cmd_show_port_flow_transfer_proxy_proxy, 14193 NULL, 14194 } 14195 }; 14196 14197 /* ******************************************************************************** */ 14198 14199 /* list of instructions */ 14200 static cmdline_parse_ctx_t builtin_ctx[] = { 14201 (cmdline_parse_inst_t *)&cmd_help_brief, 14202 (cmdline_parse_inst_t *)&cmd_help_long, 14203 (cmdline_parse_inst_t *)&cmd_quit, 14204 (cmdline_parse_inst_t *)&cmd_load_from_file, 14205 (cmdline_parse_inst_t *)&cmd_showport, 14206 (cmdline_parse_inst_t *)&cmd_showqueue, 14207 (cmdline_parse_inst_t *)&cmd_showeeprom, 14208 (cmdline_parse_inst_t *)&cmd_showportall, 14209 (cmdline_parse_inst_t *)&cmd_representor_info, 14210 (cmdline_parse_inst_t *)&cmd_showdevice, 14211 (cmdline_parse_inst_t *)&cmd_showcfg, 14212 (cmdline_parse_inst_t *)&cmd_showfwdall, 14213 (cmdline_parse_inst_t *)&cmd_start, 14214 (cmdline_parse_inst_t *)&cmd_start_tx_first, 14215 (cmdline_parse_inst_t *)&cmd_start_tx_first_n, 14216 (cmdline_parse_inst_t *)&cmd_set_link_up, 14217 (cmdline_parse_inst_t *)&cmd_set_link_down, 14218 (cmdline_parse_inst_t *)&cmd_reset, 14219 (cmdline_parse_inst_t *)&cmd_set_numbers, 14220 (cmdline_parse_inst_t *)&cmd_set_log, 14221 (cmdline_parse_inst_t *)&cmd_set_rxoffs, 14222 (cmdline_parse_inst_t *)&cmd_set_rxpkts, 14223 (cmdline_parse_inst_t *)&cmd_set_txpkts, 14224 (cmdline_parse_inst_t *)&cmd_set_txsplit, 14225 (cmdline_parse_inst_t *)&cmd_set_txtimes, 14226 (cmdline_parse_inst_t *)&cmd_set_fwd_list, 14227 (cmdline_parse_inst_t *)&cmd_set_fwd_mask, 14228 (cmdline_parse_inst_t *)&cmd_set_fwd_mode, 14229 (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode, 14230 (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry, 14231 (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one, 14232 (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all, 14233 (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one, 14234 (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all, 14235 (cmdline_parse_inst_t *)&cmd_set_flush_rx, 14236 (cmdline_parse_inst_t *)&cmd_set_link_check, 14237 (cmdline_parse_inst_t *)&cmd_set_bypass_mode, 14238 (cmdline_parse_inst_t *)&cmd_set_bypass_event, 14239 (cmdline_parse_inst_t *)&cmd_set_bypass_timeout, 14240 (cmdline_parse_inst_t *)&cmd_show_bypass_config, 14241 (cmdline_parse_inst_t *)&cmd_vlan_offload, 14242 (cmdline_parse_inst_t *)&cmd_vlan_tpid, 14243 (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all, 14244 (cmdline_parse_inst_t *)&cmd_rx_vlan_filter, 14245 (cmdline_parse_inst_t *)&cmd_tx_vlan_set, 14246 (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq, 14247 (cmdline_parse_inst_t *)&cmd_tx_vlan_reset, 14248 (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid, 14249 (cmdline_parse_inst_t *)&cmd_csum_set, 14250 (cmdline_parse_inst_t *)&cmd_csum_show, 14251 (cmdline_parse_inst_t *)&cmd_csum_tunnel, 14252 (cmdline_parse_inst_t *)&cmd_tso_set, 14253 (cmdline_parse_inst_t *)&cmd_tso_show, 14254 (cmdline_parse_inst_t *)&cmd_tunnel_tso_set, 14255 (cmdline_parse_inst_t *)&cmd_tunnel_tso_show, 14256 #ifdef RTE_LIB_GRO 14257 (cmdline_parse_inst_t *)&cmd_gro_enable, 14258 (cmdline_parse_inst_t *)&cmd_gro_flush, 14259 (cmdline_parse_inst_t *)&cmd_gro_show, 14260 #endif 14261 #ifdef RTE_LIB_GSO 14262 (cmdline_parse_inst_t *)&cmd_gso_enable, 14263 (cmdline_parse_inst_t *)&cmd_gso_size, 14264 (cmdline_parse_inst_t *)&cmd_gso_show, 14265 #endif 14266 (cmdline_parse_inst_t *)&cmd_link_flow_control_set, 14267 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx, 14268 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx, 14269 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw, 14270 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw, 14271 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt, 14272 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon, 14273 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd, 14274 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg, 14275 (cmdline_parse_inst_t *)&cmd_link_flow_control_show, 14276 (cmdline_parse_inst_t *)&cmd_priority_flow_control_set, 14277 (cmdline_parse_inst_t *)&cmd_queue_priority_flow_control_set, 14278 (cmdline_parse_inst_t *)&cmd_config_dcb, 14279 (cmdline_parse_inst_t *)&cmd_read_reg, 14280 (cmdline_parse_inst_t *)&cmd_read_reg_bit_field, 14281 (cmdline_parse_inst_t *)&cmd_read_reg_bit, 14282 (cmdline_parse_inst_t *)&cmd_write_reg, 14283 (cmdline_parse_inst_t *)&cmd_write_reg_bit_field, 14284 (cmdline_parse_inst_t *)&cmd_write_reg_bit, 14285 (cmdline_parse_inst_t *)&cmd_read_rxd_txd, 14286 (cmdline_parse_inst_t *)&cmd_stop, 14287 (cmdline_parse_inst_t *)&cmd_mac_addr, 14288 (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer, 14289 (cmdline_parse_inst_t *)&cmd_set_qmap, 14290 (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero, 14291 (cmdline_parse_inst_t *)&cmd_set_record_core_cycles, 14292 (cmdline_parse_inst_t *)&cmd_set_record_burst_stats, 14293 (cmdline_parse_inst_t *)&cmd_operate_port, 14294 (cmdline_parse_inst_t *)&cmd_operate_specific_port, 14295 (cmdline_parse_inst_t *)&cmd_operate_attach_port, 14296 (cmdline_parse_inst_t *)&cmd_operate_detach_port, 14297 (cmdline_parse_inst_t *)&cmd_operate_detach_device, 14298 (cmdline_parse_inst_t *)&cmd_set_port_setup_on, 14299 (cmdline_parse_inst_t *)&cmd_config_speed_all, 14300 (cmdline_parse_inst_t *)&cmd_config_speed_specific, 14301 (cmdline_parse_inst_t *)&cmd_config_loopback_all, 14302 (cmdline_parse_inst_t *)&cmd_config_loopback_specific, 14303 (cmdline_parse_inst_t *)&cmd_config_rx_tx, 14304 (cmdline_parse_inst_t *)&cmd_config_mtu, 14305 (cmdline_parse_inst_t *)&cmd_config_max_pkt_len, 14306 (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size, 14307 (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag, 14308 (cmdline_parse_inst_t *)&cmd_config_rss, 14309 (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size, 14310 (cmdline_parse_inst_t *)&cmd_config_rxtx_queue, 14311 (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue, 14312 (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue, 14313 (cmdline_parse_inst_t *)&cmd_config_rss_reta, 14314 (cmdline_parse_inst_t *)&cmd_showport_reta, 14315 (cmdline_parse_inst_t *)&cmd_showport_macs, 14316 (cmdline_parse_inst_t *)&cmd_show_port_flow_transfer_proxy, 14317 (cmdline_parse_inst_t *)&cmd_config_burst, 14318 (cmdline_parse_inst_t *)&cmd_config_thresh, 14319 (cmdline_parse_inst_t *)&cmd_config_threshold, 14320 (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter, 14321 (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter, 14322 (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter, 14323 (cmdline_parse_inst_t *)&cmd_queue_rate_limit, 14324 (cmdline_parse_inst_t *)&cmd_tunnel_udp_config, 14325 (cmdline_parse_inst_t *)&cmd_showport_rss_hash, 14326 (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key, 14327 (cmdline_parse_inst_t *)&cmd_config_rss_hash_key, 14328 (cmdline_parse_inst_t *)&cmd_cleanup_txq_mbufs, 14329 (cmdline_parse_inst_t *)&cmd_dump, 14330 (cmdline_parse_inst_t *)&cmd_dump_one, 14331 (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask, 14332 (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask, 14333 (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask, 14334 (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload, 14335 (cmdline_parse_inst_t *)&cmd_flow, 14336 (cmdline_parse_inst_t *)&cmd_show_port_meter_cap, 14337 (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm, 14338 (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm, 14339 (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm_rfc4115, 14340 (cmdline_parse_inst_t *)&cmd_del_port_meter_profile, 14341 (cmdline_parse_inst_t *)&cmd_create_port_meter, 14342 (cmdline_parse_inst_t *)&cmd_enable_port_meter, 14343 (cmdline_parse_inst_t *)&cmd_disable_port_meter, 14344 (cmdline_parse_inst_t *)&cmd_del_port_meter, 14345 (cmdline_parse_inst_t *)&cmd_del_port_meter_policy, 14346 (cmdline_parse_inst_t *)&cmd_set_port_meter_profile, 14347 (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table, 14348 (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask, 14349 (cmdline_parse_inst_t *)&cmd_show_port_meter_stats, 14350 (cmdline_parse_inst_t *)&cmd_mcast_addr, 14351 (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof, 14352 (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof, 14353 (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq, 14354 (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert, 14355 (cmdline_parse_inst_t *)&cmd_set_tx_loopback, 14356 (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en, 14357 (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en, 14358 (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on, 14359 (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off, 14360 (cmdline_parse_inst_t *)&cmd_set_macsec_sc, 14361 (cmdline_parse_inst_t *)&cmd_set_macsec_sa, 14362 (cmdline_parse_inst_t *)&cmd_set_vf_traffic, 14363 (cmdline_parse_inst_t *)&cmd_set_vf_rxmode, 14364 (cmdline_parse_inst_t *)&cmd_vf_rate_limit, 14365 (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter, 14366 (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr, 14367 (cmdline_parse_inst_t *)&cmd_tc_min_bw, 14368 (cmdline_parse_inst_t *)&cmd_set_vxlan, 14369 (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl, 14370 (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan, 14371 (cmdline_parse_inst_t *)&cmd_set_nvgre, 14372 (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan, 14373 (cmdline_parse_inst_t *)&cmd_set_l2_encap, 14374 (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan, 14375 (cmdline_parse_inst_t *)&cmd_set_l2_decap, 14376 (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan, 14377 (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap, 14378 (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan, 14379 (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap, 14380 (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan, 14381 (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap, 14382 (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan, 14383 (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap, 14384 (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan, 14385 (cmdline_parse_inst_t *)&cmd_set_conntrack_common, 14386 (cmdline_parse_inst_t *)&cmd_set_conntrack_dir, 14387 (cmdline_parse_inst_t *)&cmd_show_vf_stats, 14388 (cmdline_parse_inst_t *)&cmd_clear_vf_stats, 14389 (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes, 14390 (cmdline_parse_inst_t *)&cmd_set_port_ptypes, 14391 (cmdline_parse_inst_t *)&cmd_show_port_tm_cap, 14392 (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap, 14393 (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap, 14394 (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type, 14395 (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats, 14396 (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile, 14397 (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile, 14398 (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper, 14399 (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper, 14400 (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile, 14401 (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile, 14402 (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile, 14403 (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node, 14404 (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode, 14405 (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node, 14406 (cmdline_parse_inst_t *)&cmd_del_port_tm_node, 14407 (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent, 14408 (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node, 14409 (cmdline_parse_inst_t *)&cmd_resume_port_tm_node, 14410 (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit, 14411 (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn, 14412 (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp, 14413 (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei, 14414 (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port, 14415 (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa, 14416 (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration, 14417 (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload, 14418 (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload, 14419 (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa, 14420 (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration, 14421 (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload, 14422 (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload, 14423 #ifdef RTE_LIB_BPF 14424 (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse, 14425 (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse, 14426 #endif 14427 (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific, 14428 (cmdline_parse_inst_t *)&cmd_show_tx_metadata, 14429 (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status, 14430 (cmdline_parse_inst_t *)&cmd_show_rx_queue_desc_used_count, 14431 (cmdline_parse_inst_t *)&cmd_set_raw, 14432 (cmdline_parse_inst_t *)&cmd_show_set_raw, 14433 (cmdline_parse_inst_t *)&cmd_show_set_raw_all, 14434 (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific, 14435 (cmdline_parse_inst_t *)&cmd_show_fec_mode, 14436 (cmdline_parse_inst_t *)&cmd_set_fec_mode, 14437 (cmdline_parse_inst_t *)&cmd_set_rxq_avail_thresh, 14438 (cmdline_parse_inst_t *)&cmd_show_capability, 14439 (cmdline_parse_inst_t *)&cmd_set_flex_is_pattern, 14440 (cmdline_parse_inst_t *)&cmd_set_flex_spec_pattern, 14441 NULL, 14442 }; 14443 14444 void 14445 testpmd_add_driver_commands(struct testpmd_driver_commands *c) 14446 { 14447 TAILQ_INSERT_TAIL(&driver_commands_head, c, next); 14448 } 14449 14450 int 14451 init_cmdline(void) 14452 { 14453 struct testpmd_driver_commands *c; 14454 unsigned int count; 14455 unsigned int i; 14456 14457 /* initialize non-constant commands */ 14458 cmd_set_fwd_mode_init(); 14459 cmd_set_fwd_retry_mode_init(); 14460 14461 count = 0; 14462 for (i = 0; builtin_ctx[i] != NULL; i++) 14463 count++; 14464 TAILQ_FOREACH(c, &driver_commands_head, next) { 14465 for (i = 0; c->commands[i].ctx != NULL; i++) 14466 count++; 14467 } 14468 14469 /* cmdline expects a NULL terminated array */ 14470 main_ctx = calloc(count + 1, sizeof(main_ctx[0])); 14471 if (main_ctx == NULL) 14472 return -1; 14473 14474 count = 0; 14475 for (i = 0; builtin_ctx[i] != NULL; i++, count++) 14476 main_ctx[count] = builtin_ctx[i]; 14477 TAILQ_FOREACH(c, &driver_commands_head, next) { 14478 for (i = 0; c->commands[i].ctx != NULL; i++, count++) 14479 main_ctx[count] = c->commands[i].ctx; 14480 } 14481 14482 return 0; 14483 } 14484 14485 /* read cmdline commands from file */ 14486 void 14487 cmdline_read_from_file(const char *filename) 14488 { 14489 struct cmdline *cl; 14490 14491 cl = cmdline_file_new(main_ctx, "testpmd> ", filename); 14492 if (cl == NULL) { 14493 fprintf(stderr, 14494 "Failed to create file based cmdline context: %s\n", 14495 filename); 14496 return; 14497 } 14498 14499 cmdline_interact(cl); 14500 cmdline_quit(cl); 14501 14502 cmdline_free(cl); 14503 14504 printf("Read CLI commands from %s\n", filename); 14505 } 14506 14507 /* prompt function, called from main on MAIN lcore */ 14508 void 14509 prompt(void) 14510 { 14511 int ret; 14512 14513 testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> "); 14514 if (testpmd_cl == NULL) 14515 return; 14516 14517 ret = atexit(prompt_exit); 14518 if (ret != 0) 14519 fprintf(stderr, "Cannot set exit function for cmdline\n"); 14520 14521 cmdline_interact(testpmd_cl); 14522 if (ret != 0) 14523 cmdline_stdin_exit(testpmd_cl); 14524 } 14525 14526 void 14527 prompt_exit(void) 14528 { 14529 if (testpmd_cl != NULL) { 14530 cmdline_quit(testpmd_cl); 14531 cmdline_stdin_exit(testpmd_cl); 14532 } 14533 } 14534 14535 static void 14536 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue) 14537 { 14538 if (id == (portid_t)RTE_PORT_ALL) { 14539 portid_t pid; 14540 14541 RTE_ETH_FOREACH_DEV(pid) { 14542 /* check if need_reconfig has been set to 1 */ 14543 if (ports[pid].need_reconfig == 0) 14544 ports[pid].need_reconfig = dev; 14545 /* check if need_reconfig_queues has been set to 1 */ 14546 if (ports[pid].need_reconfig_queues == 0) 14547 ports[pid].need_reconfig_queues = queue; 14548 } 14549 } else if (!port_id_is_invalid(id, DISABLED_WARN)) { 14550 /* check if need_reconfig has been set to 1 */ 14551 if (ports[id].need_reconfig == 0) 14552 ports[id].need_reconfig = dev; 14553 /* check if need_reconfig_queues has been set to 1 */ 14554 if (ports[id].need_reconfig_queues == 0) 14555 ports[id].need_reconfig_queues = queue; 14556 } 14557 } 14558