1 /*- 2 * BSD LICENSE 3 * 4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * * Neither the name of Intel Corporation nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #include <stdarg.h> 35 #include <errno.h> 36 #include <stdio.h> 37 #include <stdint.h> 38 #include <stdarg.h> 39 #include <string.h> 40 #include <termios.h> 41 #include <unistd.h> 42 #include <inttypes.h> 43 #ifndef __linux__ 44 #include <net/socket.h> 45 #endif 46 #include <netinet/in.h> 47 48 #include <sys/queue.h> 49 50 #include <rte_common.h> 51 #include <rte_byteorder.h> 52 #include <rte_log.h> 53 #include <rte_debug.h> 54 #include <rte_cycles.h> 55 #include <rte_memory.h> 56 #include <rte_memzone.h> 57 #include <rte_launch.h> 58 #include <rte_tailq.h> 59 #include <rte_eal.h> 60 #include <rte_per_lcore.h> 61 #include <rte_lcore.h> 62 #include <rte_atomic.h> 63 #include <rte_branch_prediction.h> 64 #include <rte_ring.h> 65 #include <rte_mempool.h> 66 #include <rte_interrupts.h> 67 #include <rte_pci.h> 68 #include <rte_ether.h> 69 #include <rte_ethdev.h> 70 #include <rte_string_fns.h> 71 72 #include <cmdline_rdline.h> 73 #include <cmdline_parse.h> 74 #include <cmdline_parse_num.h> 75 #include <cmdline_parse_string.h> 76 #include <cmdline_parse_ipaddr.h> 77 #include <cmdline_parse_etheraddr.h> 78 #include <cmdline_socket.h> 79 #include <cmdline.h> 80 #include <rte_pci_dev_ids.h> 81 82 #include "testpmd.h" 83 84 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue); 85 86 #ifdef RTE_NIC_BYPASS 87 uint8_t bypass_is_supported(portid_t port_id); 88 #endif 89 90 /* *** Help command with introduction. *** */ 91 struct cmd_help_brief_result { 92 cmdline_fixed_string_t help; 93 }; 94 95 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result, 96 struct cmdline *cl, 97 __attribute__((unused)) void *data) 98 { 99 cmdline_printf( 100 cl, 101 "\n" 102 "Help is available for the following sections:\n\n" 103 " help control : Start and stop forwarding.\n" 104 " help display : Displaying port, stats and config " 105 "information.\n" 106 " help config : Configuration information.\n" 107 " help ports : Configuring ports.\n" 108 " help flowdir : Flow Director filter help.\n" 109 " help registers : Reading and setting port registers.\n" 110 " help all : All of the above sections.\n\n" 111 ); 112 113 } 114 115 cmdline_parse_token_string_t cmd_help_brief_help = 116 TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help"); 117 118 cmdline_parse_inst_t cmd_help_brief = { 119 .f = cmd_help_brief_parsed, 120 .data = NULL, 121 .help_str = "show help", 122 .tokens = { 123 (void *)&cmd_help_brief_help, 124 NULL, 125 }, 126 }; 127 128 /* *** Help command with help sections. *** */ 129 struct cmd_help_long_result { 130 cmdline_fixed_string_t help; 131 cmdline_fixed_string_t section; 132 }; 133 134 static void cmd_help_long_parsed(void *parsed_result, 135 struct cmdline *cl, 136 __attribute__((unused)) void *data) 137 { 138 int show_all = 0; 139 struct cmd_help_long_result *res = parsed_result; 140 141 if (!strcmp(res->section, "all")) 142 show_all = 1; 143 144 if (show_all || !strcmp(res->section, "control")) { 145 146 cmdline_printf( 147 cl, 148 "\n" 149 "Control forwarding:\n" 150 "-------------------\n\n" 151 152 "start\n" 153 " Start packet forwarding with current configuration.\n\n" 154 155 "start tx_first\n" 156 " Start packet forwarding with current config" 157 " after sending one burst of packets.\n\n" 158 159 "stop\n" 160 " Stop packet forwarding, and display accumulated" 161 " statistics.\n\n" 162 163 "quit\n" 164 " Quit to prompt in Linux and reboot on Baremetal.\n\n" 165 ); 166 } 167 168 if (show_all || !strcmp(res->section, "display")) { 169 170 cmdline_printf( 171 cl, 172 "\n" 173 "Display:\n" 174 "--------\n\n" 175 176 "show port (info|stats|fdir|stat_qmap) (port_id|all)\n" 177 " Display information for port_id, or all.\n\n" 178 179 "clear port (info|stats|fdir|stat_qmap) (port_id|all)\n" 180 " Clear information for port_id, or all.\n\n" 181 182 "show config (rxtx|cores|fwd)\n" 183 " Display the given configuration.\n\n" 184 185 "read rxd (port_id) (queue_id) (rxd_id)\n" 186 " Display an RX descriptor of a port RX queue.\n\n" 187 188 "read txd (port_id) (queue_id) (txd_id)\n" 189 " Display a TX descriptor of a port TX queue.\n\n" 190 ); 191 } 192 193 if (show_all || !strcmp(res->section, "config")) { 194 cmdline_printf( 195 cl, 196 "\n" 197 "Configuration:\n" 198 "--------------\n" 199 "Configuration changes only become active when" 200 " forwarding is started/restarted.\n\n" 201 202 "set default\n" 203 " Reset forwarding to the default configuration.\n\n" 204 205 "set verbose (level)\n" 206 " Set the debug verbosity level X.\n\n" 207 208 "set nbport (num)\n" 209 " Set number of ports.\n\n" 210 211 "set nbcore (num)\n" 212 " Set number of cores.\n\n" 213 214 "set coremask (mask)\n" 215 " Set the forwarding cores hexadecimal mask.\n\n" 216 217 "set portmask (mask)\n" 218 " Set the forwarding ports hexadecimal mask.\n\n" 219 220 "set burst (num)\n" 221 " Set number of packets per burst.\n\n" 222 223 "set txpkts (x[,y]*)\n" 224 " Set the length of each segment of TXONLY" 225 " packets.\n\n" 226 227 "set corelist (x[,y]*)\n" 228 " Set the list of forwarding cores.\n\n" 229 230 "set portlist (x[,y]*)\n" 231 " Set the list of forwarding ports.\n\n" 232 233 "vlan set strip (on|off) (port_id)\n" 234 " Set the VLAN strip on a port.\n\n" 235 236 "vlan set stripq (on|off) (port_id,queue_id)\n" 237 " Set the VLAN strip for a queue on a port.\n\n" 238 239 "vlan set filter (on|off) (port_id)\n" 240 " Set the VLAN filter on a port.\n\n" 241 242 "vlan set qinq (on|off) (port_id)\n" 243 " Set the VLAN QinQ (extended queue in queue)" 244 " on a port.\n\n" 245 246 "vlan set tpid (value) (port_id)\n" 247 " Set the outer VLAN TPID for Packet Filtering on" 248 " a port\n\n" 249 250 "rx_vlan add (vlan_id|all) (port_id)\n" 251 " Add a vlan_id, or all identifiers, to the set" 252 " of VLAN identifiers filtered by port_id.\n\n" 253 254 "rx_vlan rm (vlan_id|all) (port_id)\n" 255 " Remove a vlan_id, or all identifiers, from the set" 256 " of VLAN identifiers filtered by port_id.\n\n" 257 258 "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n" 259 " Add a vlan_id, to the set of VLAN identifiers" 260 "filtered for VF(s) from port_id.\n\n" 261 262 "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n" 263 " Remove a vlan_id, to the set of VLAN identifiers" 264 "filtered for VF(s) from port_id.\n\n" 265 266 "rx_vlan set tpid (value) (port_id)\n" 267 " Set the outer VLAN TPID for Packet Filtering on" 268 " a port\n\n" 269 270 "tx_vlan set vlan_id (port_id)\n" 271 " Set hardware insertion of VLAN ID in packets sent" 272 " on a port.\n\n" 273 274 "tx_vlan reset (port_id)\n" 275 " Disable hardware insertion of a VLAN header in" 276 " packets sent on a port.\n\n" 277 278 "tx_checksum set mask (port_id)\n" 279 " Enable hardware insertion of checksum offload with" 280 " the 4-bit mask, 0~0xf, in packets sent on a port.\n" 281 " bit 0 - insert ip checksum offload if set\n" 282 " bit 1 - insert udp checksum offload if set\n" 283 " bit 2 - insert tcp checksum offload if set\n" 284 " bit 3 - insert sctp checksum offload if set\n" 285 " Please check the NIC datasheet for HW limits.\n\n" 286 287 #ifdef RTE_LIBRTE_IEEE1588 288 "set fwd (io|mac|rxonly|txonly|csum|ieee1588)\n" 289 " Set IO, MAC, RXONLY, CSUM or TXONLY or ieee1588" 290 " packet forwarding mode.\n\n" 291 292 #else 293 "set fwd (io|mac|rxonly|txonly|csum)\n" 294 " Set IO, MAC, RXONLY, CSUM or TXONLY packet" 295 " forwarding mode.\n\n" 296 297 #endif 298 "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n" 299 " Add a MAC address on port_id.\n\n" 300 301 "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n" 302 " Remove a MAC address from port_id.\n\n" 303 304 "mac_addr add port (port_id) vf (vf_id) (mac_address)\n" 305 " Add a MAC address for a VF on the port.\n\n" 306 307 "set port (port_id) uta (mac_address|all) (on|off)\n" 308 " Add/Remove a or all unicast hash filter(s)" 309 "from port X.\n\n" 310 311 "set promisc (port_id|all) (on|off)\n" 312 " Set the promiscuous mode on port_id, or all.\n\n" 313 314 "set allmulti (port_id|all) (on|off)\n" 315 " Set the allmulti mode on port_id, or all.\n\n" 316 317 "set flow_ctrl rx (on|off) tx (on|off) (high_water)" 318 " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd" 319 " (on|off) (port_id)\n" 320 " Set the link flow control parameter on a port.\n\n" 321 322 "set pfc_ctrl rx (on|off) tx (on|off) (high_water)" 323 " (low_water) (pause_time) (priority) (port_id)\n" 324 " Set the priority flow control parameter on a" 325 " port.\n\n" 326 327 "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n" 328 " Set statistics mapping (qmapping 0..15) for RX/TX" 329 " queue on port.\n" 330 " e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2" 331 " on port 0 to mapping 5.\n\n" 332 333 "set port (port_id) vf (vf_id) rx|tx on|off \n" 334 " Enable/Disable a VF receive/tranmit from a port\n\n" 335 336 "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM" 337 "|MPE) (on|off)\n" 338 " AUPE:accepts untagged VLAN;" 339 "ROPE:accept unicast hash\n\n" 340 " BAM:accepts broadcast packets;" 341 "MPE:accepts all multicast packets\n\n" 342 " Enable/Disable a VF receive mode of a port\n\n" 343 344 "set port (port_id) mirror-rule (rule_id)" 345 "(pool-mirror|vlan-mirror)\n" 346 " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n" 347 " Set pool or vlan type mirror rule on a port.\n" 348 " e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1" 349 " dst-pool 0 on' enable mirror traffic with vlan 0,1" 350 " to pool 0.\n\n" 351 352 "set port (port_id) mirror-rule (rule_id)" 353 " (uplink-mirror|downlink-mirror) dst-pool" 354 " (pool_id) (on|off)\n" 355 " Set uplink or downlink type mirror rule on a port.\n" 356 " e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool" 357 " 0 on' enable mirror income traffic to pool 0.\n\n" 358 359 "reset port (port_id) mirror-rule (rule_id)\n" 360 " Reset a mirror rule.\n\n" 361 362 "set flush_rx (on|off)\n" 363 " Flush (default) or don't flush RX streams before" 364 " forwarding. Mainly used with PCAP drivers.\n\n" 365 366 #ifdef RTE_NIC_BYPASS 367 "set bypass mode (normal|bypass|isolate) (port_id)\n" 368 " Set the bypass mode for the lowest port on bypass enabled" 369 " NIC.\n\n" 370 371 "set bypass event (timeout|os_on|os_off|power_on|power_off) " 372 "mode (normal|bypass|isolate) (port_id)\n" 373 " Set the event required to initiate specified bypass mode for" 374 " the lowest port on a bypass enabled NIC where:\n" 375 " timeout = enable bypass after watchdog timeout.\n" 376 " os_on = enable bypass when OS/board is powered on.\n" 377 " os_off = enable bypass when OS/board is powered off.\n" 378 " power_on = enable bypass when power supply is turned on.\n" 379 " power_off = enable bypass when power supply is turned off." 380 "\n\n" 381 382 "set bypass timeout (0|1.5|2|3|4|8|16|32)\n" 383 " Set the bypass watchdog timeout to 'n' seconds" 384 " where 0 = instant.\n\n" 385 386 "show bypass config (port_id)\n" 387 " Show the bypass configuration for a bypass enabled NIC" 388 " using the lowest port on the NIC.\n\n" 389 #endif 390 391 ); 392 } 393 394 395 if (show_all || !strcmp(res->section, "flowdir")) { 396 397 cmdline_printf( 398 cl, 399 "\n" 400 "Flow director mode:\n" 401 "-------------------\n\n" 402 403 "add_signature_filter (port_id) (ip|udp|tcp|sctp)" 404 " src (src_ip_address) (src_port)" 405 " dst (dst_ip_address) (dst_port)" 406 " flexbytes (flexbytes_values) vlan (vlan_id)" 407 " queue (queue_id)\n" 408 " Add a signature filter.\n\n" 409 410 "upd_signature_filter (port_id) (ip|udp|tcp|sctp)" 411 " src (src_ip_address) (src_port)" 412 " dst (dst_ip_address) (dst_port)" 413 " flexbytes (flexbytes_values) vlan (vlan_id)" 414 " queue (queue_id)\n" 415 " Update a signature filter.\n\n" 416 417 "rm_signature_filter (port_id) (ip|udp|tcp|sctp)" 418 " src (src_ip_address) (src_port)" 419 " dst (dst_ip_address) (dst_port)" 420 " flexbytes (flexbytes_values) vlan (vlan_id)\n" 421 " Remove a signature filter.\n\n" 422 423 "add_perfect_filter (port_id) (ip|udp|tcp|sctp)" 424 " src (src_ip_address) (src_port)" 425 " dst (dst_ip_address) (dst_port)" 426 " flexbytes (flexbytes_values) vlan (vlan_id)" 427 " queue (queue_id) soft (soft_id)\n" 428 " Add a perfect filter.\n\n" 429 430 "upd_perfect_filter (port_id) (ip|udp|tcp|sctp)" 431 " src (src_ip_address) (src_port)" 432 " dst (dst_ip_address) (dst_port)" 433 " flexbytes (flexbytes_values) vlan (vlan_id)" 434 " queue (queue_id)\n" 435 " Update a perfect filter.\n\n" 436 437 "rm_perfect_filter (port_id) (ip|udp|tcp|sctp)" 438 " src (src_ip_address) (src_port)" 439 " dst (dst_ip_address) (dst_port)" 440 " flexbytes (flexbytes_values) vlan (vlan_id)" 441 " soft (soft_id)\n" 442 " Remove a perfect filter.\n\n" 443 444 "set_masks_filter (port_id) only_ip_flow (0|1)" 445 " src_mask (ip_src_mask) (src_port_mask)" 446 " dst_mask (ip_dst_mask) (dst_port_mask)" 447 " flexbytes (0|1) vlan_id (0|1) vlan_prio (0|1)\n" 448 " Set IPv4 filter masks.\n\n" 449 450 "set_ipv6_masks_filter (port_id) only_ip_flow (0|1)" 451 " src_mask (ip_src_mask) (src_port_mask)" 452 " dst_mask (ip_dst_mask) (dst_port_mask)" 453 " flexbytes (0|1) vlan_id (0|1) vlan_prio (0|1)" 454 " compare_dst (0|1)\n" 455 " Set IPv6 filter masks.\n\n" 456 ); 457 } 458 459 if (show_all || !strcmp(res->section, "ports")) { 460 461 cmdline_printf( 462 cl, 463 "\n" 464 "Port Operations:\n" 465 "----------------\n\n" 466 467 "port start (port_id|all)\n" 468 " Start all ports or port_id.\n\n" 469 470 "port stop (port_id|all)\n" 471 " Stop all ports or port_id.\n\n" 472 473 "port close (port_id|all)\n" 474 " Close all ports or port_id.\n\n" 475 476 "port config (port_id|all) speed (10|100|1000|10000|auto)" 477 " duplex (half|full|auto)\n" 478 " Set speed and duplex for all ports or port_id\n\n" 479 480 "port config all (rxq|txq|rxd|txd) (value)\n" 481 " Set number for rxq/txq/rxd/txd.\n\n" 482 483 "port config all max-pkt-len (value)\n" 484 " Set the max packet length.\n\n" 485 486 "port config all (crc-strip|rx-cksum|hw-vlan|drop-en)" 487 " (on|off)\n" 488 " Set crc-strip/rx-checksum/hardware-vlan/drop_en" 489 " for ports.\n\n" 490 491 "port config all rss (ip|udp|none)\n" 492 " Set the RSS mode.\n\n" 493 494 "port config port-id rss reta (hash,queue)[,(hash,queue)]\n" 495 " Set the RSS redirection table.\n\n" 496 497 "port config (port_id) dcb vt (on|off) (traffic_class)" 498 " pfc (on|off)\n" 499 " Set the DCB mode.\n\n" 500 501 "port config all burst (value)\n" 502 " Set the number of packets per burst.\n\n" 503 504 "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)" 505 " (value)\n" 506 " Set the ring prefetch/host/writeback threshold" 507 " for tx/rx queue.\n\n" 508 509 "port config all (txfreet|txrst|rxfreet) (value)\n" 510 " Set free threshold for rx/tx, or set" 511 " tx rs bit threshold.\n\n" 512 ); 513 } 514 515 if (show_all || !strcmp(res->section, "registers")) { 516 517 cmdline_printf( 518 cl, 519 "\n" 520 "Registers:\n" 521 "----------\n\n" 522 523 "read reg (port_id) (address)\n" 524 " Display value of a port register.\n\n" 525 526 "read regfield (port_id) (address) (bit_x) (bit_y)\n" 527 " Display a port register bit field.\n\n" 528 529 "read regbit (port_id) (address) (bit_x)\n" 530 " Display a single port register bit.\n\n" 531 532 "write reg (port_id) (address) (value)\n" 533 " Set value of a port register.\n\n" 534 535 "write regfield (port_id) (address) (bit_x) (bit_y)" 536 " (value)\n" 537 " Set bit field of a port register.\n\n" 538 539 "write regbit (port_id) (address) (bit_x) (value)\n" 540 " Set single bit value of a port register.\n\n" 541 ); 542 } 543 } 544 545 cmdline_parse_token_string_t cmd_help_long_help = 546 TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help"); 547 548 cmdline_parse_token_string_t cmd_help_long_section = 549 TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section, 550 "all#control#display#config#flowdir#" 551 "ports#registers"); 552 553 cmdline_parse_inst_t cmd_help_long = { 554 .f = cmd_help_long_parsed, 555 .data = NULL, 556 .help_str = "show help", 557 .tokens = { 558 (void *)&cmd_help_long_help, 559 (void *)&cmd_help_long_section, 560 NULL, 561 }, 562 }; 563 564 565 /* *** start/stop/close all ports *** */ 566 struct cmd_operate_port_result { 567 cmdline_fixed_string_t keyword; 568 cmdline_fixed_string_t name; 569 cmdline_fixed_string_t value; 570 }; 571 572 static void cmd_operate_port_parsed(void *parsed_result, 573 __attribute__((unused)) struct cmdline *cl, 574 __attribute__((unused)) void *data) 575 { 576 struct cmd_operate_port_result *res = parsed_result; 577 578 if (!strcmp(res->name, "start")) 579 start_port(RTE_PORT_ALL); 580 else if (!strcmp(res->name, "stop")) 581 stop_port(RTE_PORT_ALL); 582 else if (!strcmp(res->name, "close")) 583 close_port(RTE_PORT_ALL); 584 else 585 printf("Unknown parameter\n"); 586 } 587 588 cmdline_parse_token_string_t cmd_operate_port_all_cmd = 589 TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword, 590 "port"); 591 cmdline_parse_token_string_t cmd_operate_port_all_port = 592 TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name, 593 "start#stop#close"); 594 cmdline_parse_token_string_t cmd_operate_port_all_all = 595 TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all"); 596 597 cmdline_parse_inst_t cmd_operate_port = { 598 .f = cmd_operate_port_parsed, 599 .data = NULL, 600 .help_str = "port start|stop|close all: start/stop/close all ports", 601 .tokens = { 602 (void *)&cmd_operate_port_all_cmd, 603 (void *)&cmd_operate_port_all_port, 604 (void *)&cmd_operate_port_all_all, 605 NULL, 606 }, 607 }; 608 609 /* *** start/stop/close specific port *** */ 610 struct cmd_operate_specific_port_result { 611 cmdline_fixed_string_t keyword; 612 cmdline_fixed_string_t name; 613 uint8_t value; 614 }; 615 616 static void cmd_operate_specific_port_parsed(void *parsed_result, 617 __attribute__((unused)) struct cmdline *cl, 618 __attribute__((unused)) void *data) 619 { 620 struct cmd_operate_specific_port_result *res = parsed_result; 621 622 if (!strcmp(res->name, "start")) 623 start_port(res->value); 624 else if (!strcmp(res->name, "stop")) 625 stop_port(res->value); 626 else if (!strcmp(res->name, "close")) 627 close_port(res->value); 628 else 629 printf("Unknown parameter\n"); 630 } 631 632 cmdline_parse_token_string_t cmd_operate_specific_port_cmd = 633 TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result, 634 keyword, "port"); 635 cmdline_parse_token_string_t cmd_operate_specific_port_port = 636 TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result, 637 name, "start#stop#close"); 638 cmdline_parse_token_num_t cmd_operate_specific_port_id = 639 TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result, 640 value, UINT8); 641 642 cmdline_parse_inst_t cmd_operate_specific_port = { 643 .f = cmd_operate_specific_port_parsed, 644 .data = NULL, 645 .help_str = "port start|stop|close X: start/stop/close port X", 646 .tokens = { 647 (void *)&cmd_operate_specific_port_cmd, 648 (void *)&cmd_operate_specific_port_port, 649 (void *)&cmd_operate_specific_port_id, 650 NULL, 651 }, 652 }; 653 654 /* *** configure speed for all ports *** */ 655 struct cmd_config_speed_all { 656 cmdline_fixed_string_t port; 657 cmdline_fixed_string_t keyword; 658 cmdline_fixed_string_t all; 659 cmdline_fixed_string_t item1; 660 cmdline_fixed_string_t item2; 661 cmdline_fixed_string_t value1; 662 cmdline_fixed_string_t value2; 663 }; 664 665 static void 666 cmd_config_speed_all_parsed(void *parsed_result, 667 __attribute__((unused)) struct cmdline *cl, 668 __attribute__((unused)) void *data) 669 { 670 struct cmd_config_speed_all *res = parsed_result; 671 uint16_t link_speed = ETH_LINK_SPEED_AUTONEG; 672 uint16_t link_duplex = 0; 673 portid_t pid; 674 675 if (!all_ports_stopped()) { 676 printf("Please stop all ports first\n"); 677 return; 678 } 679 680 if (!strcmp(res->value1, "10")) 681 link_speed = ETH_LINK_SPEED_10; 682 else if (!strcmp(res->value1, "100")) 683 link_speed = ETH_LINK_SPEED_100; 684 else if (!strcmp(res->value1, "1000")) 685 link_speed = ETH_LINK_SPEED_1000; 686 else if (!strcmp(res->value1, "10000")) 687 link_speed = ETH_LINK_SPEED_10000; 688 else if (!strcmp(res->value1, "auto")) 689 link_speed = ETH_LINK_SPEED_AUTONEG; 690 else { 691 printf("Unknown parameter\n"); 692 return; 693 } 694 695 if (!strcmp(res->value2, "half")) 696 link_duplex = ETH_LINK_HALF_DUPLEX; 697 else if (!strcmp(res->value2, "full")) 698 link_duplex = ETH_LINK_FULL_DUPLEX; 699 else if (!strcmp(res->value2, "auto")) 700 link_duplex = ETH_LINK_AUTONEG_DUPLEX; 701 else { 702 printf("Unknown parameter\n"); 703 return; 704 } 705 706 for (pid = 0; pid < nb_ports; pid++) { 707 ports[pid].dev_conf.link_speed = link_speed; 708 ports[pid].dev_conf.link_duplex = link_duplex; 709 } 710 711 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 712 } 713 714 cmdline_parse_token_string_t cmd_config_speed_all_port = 715 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port"); 716 cmdline_parse_token_string_t cmd_config_speed_all_keyword = 717 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword, 718 "config"); 719 cmdline_parse_token_string_t cmd_config_speed_all_all = 720 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all"); 721 cmdline_parse_token_string_t cmd_config_speed_all_item1 = 722 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed"); 723 cmdline_parse_token_string_t cmd_config_speed_all_value1 = 724 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1, 725 "10#100#1000#10000#auto"); 726 cmdline_parse_token_string_t cmd_config_speed_all_item2 = 727 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex"); 728 cmdline_parse_token_string_t cmd_config_speed_all_value2 = 729 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2, 730 "half#full#auto"); 731 732 cmdline_parse_inst_t cmd_config_speed_all = { 733 .f = cmd_config_speed_all_parsed, 734 .data = NULL, 735 .help_str = "port config all speed 10|100|1000|10000|auto duplex " 736 "half|full|auto", 737 .tokens = { 738 (void *)&cmd_config_speed_all_port, 739 (void *)&cmd_config_speed_all_keyword, 740 (void *)&cmd_config_speed_all_all, 741 (void *)&cmd_config_speed_all_item1, 742 (void *)&cmd_config_speed_all_value1, 743 (void *)&cmd_config_speed_all_item2, 744 (void *)&cmd_config_speed_all_value2, 745 NULL, 746 }, 747 }; 748 749 /* *** configure speed for specific port *** */ 750 struct cmd_config_speed_specific { 751 cmdline_fixed_string_t port; 752 cmdline_fixed_string_t keyword; 753 uint8_t id; 754 cmdline_fixed_string_t item1; 755 cmdline_fixed_string_t item2; 756 cmdline_fixed_string_t value1; 757 cmdline_fixed_string_t value2; 758 }; 759 760 static void 761 cmd_config_speed_specific_parsed(void *parsed_result, 762 __attribute__((unused)) struct cmdline *cl, 763 __attribute__((unused)) void *data) 764 { 765 struct cmd_config_speed_specific *res = parsed_result; 766 uint16_t link_speed = ETH_LINK_SPEED_AUTONEG; 767 uint16_t link_duplex = 0; 768 769 if (!all_ports_stopped()) { 770 printf("Please stop all ports first\n"); 771 return; 772 } 773 774 if (res->id >= nb_ports) { 775 printf("Port id %d must be less than %d\n", res->id, nb_ports); 776 return; 777 } 778 779 if (!strcmp(res->value1, "10")) 780 link_speed = ETH_LINK_SPEED_10; 781 else if (!strcmp(res->value1, "100")) 782 link_speed = ETH_LINK_SPEED_100; 783 else if (!strcmp(res->value1, "1000")) 784 link_speed = ETH_LINK_SPEED_1000; 785 else if (!strcmp(res->value1, "10000")) 786 link_speed = ETH_LINK_SPEED_10000; 787 else if (!strcmp(res->value1, "auto")) 788 link_speed = ETH_LINK_SPEED_AUTONEG; 789 else { 790 printf("Unknown parameter\n"); 791 return; 792 } 793 794 if (!strcmp(res->value2, "half")) 795 link_duplex = ETH_LINK_HALF_DUPLEX; 796 else if (!strcmp(res->value2, "full")) 797 link_duplex = ETH_LINK_FULL_DUPLEX; 798 else if (!strcmp(res->value2, "auto")) 799 link_duplex = ETH_LINK_AUTONEG_DUPLEX; 800 else { 801 printf("Unknown parameter\n"); 802 return; 803 } 804 805 ports[res->id].dev_conf.link_speed = link_speed; 806 ports[res->id].dev_conf.link_duplex = link_duplex; 807 808 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 809 } 810 811 812 cmdline_parse_token_string_t cmd_config_speed_specific_port = 813 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port, 814 "port"); 815 cmdline_parse_token_string_t cmd_config_speed_specific_keyword = 816 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword, 817 "config"); 818 cmdline_parse_token_num_t cmd_config_speed_specific_id = 819 TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8); 820 cmdline_parse_token_string_t cmd_config_speed_specific_item1 = 821 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1, 822 "speed"); 823 cmdline_parse_token_string_t cmd_config_speed_specific_value1 = 824 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1, 825 "10#100#1000#10000#auto"); 826 cmdline_parse_token_string_t cmd_config_speed_specific_item2 = 827 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2, 828 "duplex"); 829 cmdline_parse_token_string_t cmd_config_speed_specific_value2 = 830 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2, 831 "half#full#auto"); 832 833 cmdline_parse_inst_t cmd_config_speed_specific = { 834 .f = cmd_config_speed_specific_parsed, 835 .data = NULL, 836 .help_str = "port config X speed 10|100|1000|10000|auto duplex " 837 "half|full|auto", 838 .tokens = { 839 (void *)&cmd_config_speed_specific_port, 840 (void *)&cmd_config_speed_specific_keyword, 841 (void *)&cmd_config_speed_specific_id, 842 (void *)&cmd_config_speed_specific_item1, 843 (void *)&cmd_config_speed_specific_value1, 844 (void *)&cmd_config_speed_specific_item2, 845 (void *)&cmd_config_speed_specific_value2, 846 NULL, 847 }, 848 }; 849 850 /* *** configure txq/rxq, txd/rxd *** */ 851 struct cmd_config_rx_tx { 852 cmdline_fixed_string_t port; 853 cmdline_fixed_string_t keyword; 854 cmdline_fixed_string_t all; 855 cmdline_fixed_string_t name; 856 uint16_t value; 857 }; 858 859 static void 860 cmd_config_rx_tx_parsed(void *parsed_result, 861 __attribute__((unused)) struct cmdline *cl, 862 __attribute__((unused)) void *data) 863 { 864 struct cmd_config_rx_tx *res = parsed_result; 865 866 if (!all_ports_stopped()) { 867 printf("Please stop all ports first\n"); 868 return; 869 } 870 871 if (!strcmp(res->name, "rxq")) { 872 if (res->value <= 0) { 873 printf("rxq %d invalid - must be > 0\n", res->value); 874 return; 875 } 876 nb_rxq = res->value; 877 } 878 else if (!strcmp(res->name, "txq")) { 879 if (res->value <= 0) { 880 printf("txq %d invalid - must be > 0\n", res->value); 881 return; 882 } 883 nb_txq = res->value; 884 } 885 else if (!strcmp(res->name, "rxd")) { 886 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) { 887 printf("rxd %d invalid - must be > 0 && <= %d\n", 888 res->value, RTE_TEST_RX_DESC_MAX); 889 return; 890 } 891 nb_rxd = res->value; 892 } else if (!strcmp(res->name, "txd")) { 893 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) { 894 printf("txd %d invalid - must be > 0 && <= %d\n", 895 res->value, RTE_TEST_TX_DESC_MAX); 896 return; 897 } 898 nb_txd = res->value; 899 } else { 900 printf("Unknown parameter\n"); 901 return; 902 } 903 904 init_port_config(); 905 906 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 907 } 908 909 cmdline_parse_token_string_t cmd_config_rx_tx_port = 910 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port"); 911 cmdline_parse_token_string_t cmd_config_rx_tx_keyword = 912 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config"); 913 cmdline_parse_token_string_t cmd_config_rx_tx_all = 914 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all"); 915 cmdline_parse_token_string_t cmd_config_rx_tx_name = 916 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name, 917 "rxq#txq#rxd#txd"); 918 cmdline_parse_token_num_t cmd_config_rx_tx_value = 919 TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16); 920 921 cmdline_parse_inst_t cmd_config_rx_tx = { 922 .f = cmd_config_rx_tx_parsed, 923 .data = NULL, 924 .help_str = "port config all rxq|txq|rxd|txd value", 925 .tokens = { 926 (void *)&cmd_config_rx_tx_port, 927 (void *)&cmd_config_rx_tx_keyword, 928 (void *)&cmd_config_rx_tx_all, 929 (void *)&cmd_config_rx_tx_name, 930 (void *)&cmd_config_rx_tx_value, 931 NULL, 932 }, 933 }; 934 935 /* *** config max packet length *** */ 936 struct cmd_config_max_pkt_len_result { 937 cmdline_fixed_string_t port; 938 cmdline_fixed_string_t keyword; 939 cmdline_fixed_string_t all; 940 cmdline_fixed_string_t name; 941 uint32_t value; 942 }; 943 944 static void 945 cmd_config_max_pkt_len_parsed(void *parsed_result, 946 __attribute__((unused)) struct cmdline *cl, 947 __attribute__((unused)) void *data) 948 { 949 struct cmd_config_max_pkt_len_result *res = parsed_result; 950 951 if (!all_ports_stopped()) { 952 printf("Please stop all ports first\n"); 953 return; 954 } 955 956 if (!strcmp(res->name, "max-pkt-len")) { 957 if (res->value < ETHER_MIN_LEN) { 958 printf("max-pkt-len can not be less than %d\n", 959 ETHER_MIN_LEN); 960 return; 961 } 962 if (res->value == rx_mode.max_rx_pkt_len) 963 return; 964 965 rx_mode.max_rx_pkt_len = res->value; 966 if (res->value > ETHER_MAX_LEN) 967 rx_mode.jumbo_frame = 1; 968 else 969 rx_mode.jumbo_frame = 0; 970 } else { 971 printf("Unknown parameter\n"); 972 return; 973 } 974 975 init_port_config(); 976 977 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 978 } 979 980 cmdline_parse_token_string_t cmd_config_max_pkt_len_port = 981 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port, 982 "port"); 983 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword = 984 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword, 985 "config"); 986 cmdline_parse_token_string_t cmd_config_max_pkt_len_all = 987 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all, 988 "all"); 989 cmdline_parse_token_string_t cmd_config_max_pkt_len_name = 990 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name, 991 "max-pkt-len"); 992 cmdline_parse_token_num_t cmd_config_max_pkt_len_value = 993 TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value, 994 UINT32); 995 996 cmdline_parse_inst_t cmd_config_max_pkt_len = { 997 .f = cmd_config_max_pkt_len_parsed, 998 .data = NULL, 999 .help_str = "port config all max-pkt-len value", 1000 .tokens = { 1001 (void *)&cmd_config_max_pkt_len_port, 1002 (void *)&cmd_config_max_pkt_len_keyword, 1003 (void *)&cmd_config_max_pkt_len_all, 1004 (void *)&cmd_config_max_pkt_len_name, 1005 (void *)&cmd_config_max_pkt_len_value, 1006 NULL, 1007 }, 1008 }; 1009 1010 /* *** configure rx mode *** */ 1011 struct cmd_config_rx_mode_flag { 1012 cmdline_fixed_string_t port; 1013 cmdline_fixed_string_t keyword; 1014 cmdline_fixed_string_t all; 1015 cmdline_fixed_string_t name; 1016 cmdline_fixed_string_t value; 1017 }; 1018 1019 static void 1020 cmd_config_rx_mode_flag_parsed(void *parsed_result, 1021 __attribute__((unused)) struct cmdline *cl, 1022 __attribute__((unused)) void *data) 1023 { 1024 struct cmd_config_rx_mode_flag *res = parsed_result; 1025 1026 if (!all_ports_stopped()) { 1027 printf("Please stop all ports first\n"); 1028 return; 1029 } 1030 1031 if (!strcmp(res->name, "crc-strip")) { 1032 if (!strcmp(res->value, "on")) 1033 rx_mode.hw_strip_crc = 1; 1034 else if (!strcmp(res->value, "off")) 1035 rx_mode.hw_strip_crc = 0; 1036 else { 1037 printf("Unknown parameter\n"); 1038 return; 1039 } 1040 } else if (!strcmp(res->name, "rx-cksum")) { 1041 if (!strcmp(res->value, "on")) 1042 rx_mode.hw_ip_checksum = 1; 1043 else if (!strcmp(res->value, "off")) 1044 rx_mode.hw_ip_checksum = 0; 1045 else { 1046 printf("Unknown parameter\n"); 1047 return; 1048 } 1049 } else if (!strcmp(res->name, "hw-vlan")) { 1050 if (!strcmp(res->value, "on")) { 1051 rx_mode.hw_vlan_filter = 1; 1052 rx_mode.hw_vlan_strip = 1; 1053 } 1054 else if (!strcmp(res->value, "off")) { 1055 rx_mode.hw_vlan_filter = 0; 1056 rx_mode.hw_vlan_strip = 0; 1057 } 1058 else { 1059 printf("Unknown parameter\n"); 1060 return; 1061 } 1062 } else if (!strcmp(res->name, "drop-en")) { 1063 if (!strcmp(res->value, "on")) 1064 rx_drop_en = 1; 1065 else if (!strcmp(res->value, "off")) 1066 rx_drop_en = 0; 1067 else { 1068 printf("Unknown parameter\n"); 1069 return; 1070 } 1071 } else { 1072 printf("Unknown parameter\n"); 1073 return; 1074 } 1075 1076 init_port_config(); 1077 1078 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1079 } 1080 1081 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port = 1082 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port"); 1083 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword = 1084 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword, 1085 "config"); 1086 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all = 1087 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all"); 1088 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name = 1089 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name, 1090 "crc-strip#rx-cksum#hw-vlan"); 1091 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value = 1092 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value, 1093 "on#off"); 1094 1095 cmdline_parse_inst_t cmd_config_rx_mode_flag = { 1096 .f = cmd_config_rx_mode_flag_parsed, 1097 .data = NULL, 1098 .help_str = "port config all crc-strip|rx-cksum|hw-vlan on|off", 1099 .tokens = { 1100 (void *)&cmd_config_rx_mode_flag_port, 1101 (void *)&cmd_config_rx_mode_flag_keyword, 1102 (void *)&cmd_config_rx_mode_flag_all, 1103 (void *)&cmd_config_rx_mode_flag_name, 1104 (void *)&cmd_config_rx_mode_flag_value, 1105 NULL, 1106 }, 1107 }; 1108 1109 /* *** configure rss *** */ 1110 struct cmd_config_rss { 1111 cmdline_fixed_string_t port; 1112 cmdline_fixed_string_t keyword; 1113 cmdline_fixed_string_t all; 1114 cmdline_fixed_string_t name; 1115 cmdline_fixed_string_t value; 1116 }; 1117 1118 static void 1119 cmd_config_rss_parsed(void *parsed_result, 1120 __attribute__((unused)) struct cmdline *cl, 1121 __attribute__((unused)) void *data) 1122 { 1123 struct cmd_config_rss *res = parsed_result; 1124 1125 if (!all_ports_stopped()) { 1126 printf("Please stop all ports first\n"); 1127 return; 1128 } 1129 1130 if (!strcmp(res->value, "ip")) 1131 rss_hf = ETH_RSS_IPV4 | ETH_RSS_IPV6; 1132 else if (!strcmp(res->value, "udp")) 1133 rss_hf = ETH_RSS_IPV4 | ETH_RSS_IPV6 | ETH_RSS_IPV4_UDP; 1134 else if (!strcmp(res->value, "none")) 1135 rss_hf = 0; 1136 else { 1137 printf("Unknown parameter\n"); 1138 return; 1139 } 1140 1141 init_port_config(); 1142 1143 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1144 } 1145 1146 cmdline_parse_token_string_t cmd_config_rss_port = 1147 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port"); 1148 cmdline_parse_token_string_t cmd_config_rss_keyword = 1149 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config"); 1150 cmdline_parse_token_string_t cmd_config_rss_all = 1151 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all"); 1152 cmdline_parse_token_string_t cmd_config_rss_name = 1153 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss"); 1154 cmdline_parse_token_string_t cmd_config_rss_value = 1155 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, "ip#udp#none"); 1156 1157 cmdline_parse_inst_t cmd_config_rss = { 1158 .f = cmd_config_rss_parsed, 1159 .data = NULL, 1160 .help_str = "port config all rss ip|udp|none", 1161 .tokens = { 1162 (void *)&cmd_config_rss_port, 1163 (void *)&cmd_config_rss_keyword, 1164 (void *)&cmd_config_rss_all, 1165 (void *)&cmd_config_rss_name, 1166 (void *)&cmd_config_rss_value, 1167 NULL, 1168 }, 1169 }; 1170 1171 /* *** Configure RSS RETA *** */ 1172 struct cmd_config_rss_reta { 1173 cmdline_fixed_string_t port; 1174 cmdline_fixed_string_t keyword; 1175 uint8_t port_id; 1176 cmdline_fixed_string_t name; 1177 cmdline_fixed_string_t list_name; 1178 cmdline_fixed_string_t list_of_items; 1179 }; 1180 1181 static int 1182 parse_reta_config(const char *str, struct rte_eth_rss_reta *reta_conf) 1183 { 1184 int i; 1185 unsigned size; 1186 uint8_t hash_index; 1187 uint8_t nb_queue; 1188 char s[256]; 1189 const char *p, *p0 = str; 1190 char *end; 1191 enum fieldnames { 1192 FLD_HASH_INDEX = 0, 1193 FLD_QUEUE, 1194 _NUM_FLD 1195 }; 1196 unsigned long int_fld[_NUM_FLD]; 1197 char *str_fld[_NUM_FLD]; 1198 1199 while ((p = strchr(p0,'(')) != NULL) { 1200 ++p; 1201 if((p0 = strchr(p,')')) == NULL) 1202 return -1; 1203 1204 size = p0 - p; 1205 if(size >= sizeof(s)) 1206 return -1; 1207 1208 rte_snprintf(s, sizeof(s), "%.*s", size, p); 1209 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD) 1210 return -1; 1211 for (i = 0; i < _NUM_FLD; i++) { 1212 errno = 0; 1213 int_fld[i] = strtoul(str_fld[i], &end, 0); 1214 if (errno != 0 || end == str_fld[i] || int_fld[i] > 255) 1215 return -1; 1216 } 1217 1218 hash_index = (uint8_t)int_fld[FLD_HASH_INDEX]; 1219 nb_queue = (uint8_t)int_fld[FLD_QUEUE]; 1220 1221 if (hash_index >= ETH_RSS_RETA_NUM_ENTRIES) { 1222 printf("Invalid RETA hash index=%d",hash_index); 1223 return -1; 1224 } 1225 1226 if (hash_index < ETH_RSS_RETA_NUM_ENTRIES/2) 1227 reta_conf->mask_lo |= (1ULL << hash_index); 1228 else 1229 reta_conf->mask_hi |= (1ULL << (hash_index - ETH_RSS_RETA_NUM_ENTRIES/2)); 1230 1231 reta_conf->reta[hash_index] = nb_queue; 1232 } 1233 1234 return 0; 1235 } 1236 1237 static void 1238 cmd_set_rss_reta_parsed(void *parsed_result, 1239 __attribute__((unused)) struct cmdline *cl, 1240 __attribute__((unused)) void *data) 1241 { 1242 int ret; 1243 struct rte_eth_rss_reta reta_conf; 1244 struct cmd_config_rss_reta *res = parsed_result; 1245 1246 memset(&reta_conf,0,sizeof(struct rte_eth_rss_reta)); 1247 if (!strcmp(res->list_name, "reta")) { 1248 if (parse_reta_config(res->list_of_items, &reta_conf)) { 1249 printf("Invalid RSS Redirection Table config entered\n"); 1250 return; 1251 } 1252 ret = rte_eth_dev_rss_reta_update(res->port_id, &reta_conf); 1253 if (ret != 0) 1254 printf("Bad redirection table parameter, return code = %d \n",ret); 1255 } 1256 } 1257 1258 cmdline_parse_token_string_t cmd_config_rss_reta_port = 1259 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port"); 1260 cmdline_parse_token_string_t cmd_config_rss_reta_keyword = 1261 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config"); 1262 cmdline_parse_token_num_t cmd_config_rss_reta_port_id = 1263 TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8); 1264 cmdline_parse_token_string_t cmd_config_rss_reta_name = 1265 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss"); 1266 cmdline_parse_token_string_t cmd_config_rss_reta_list_name = 1267 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta"); 1268 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items = 1269 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items, 1270 NULL); 1271 cmdline_parse_inst_t cmd_config_rss_reta = { 1272 .f = cmd_set_rss_reta_parsed, 1273 .data = NULL, 1274 .help_str = "port config X rss reta (hash,queue)[,(hash,queue)]", 1275 .tokens = { 1276 (void *)&cmd_config_rss_reta_port, 1277 (void *)&cmd_config_rss_reta_keyword, 1278 (void *)&cmd_config_rss_reta_port_id, 1279 (void *)&cmd_config_rss_reta_name, 1280 (void *)&cmd_config_rss_reta_list_name, 1281 (void *)&cmd_config_rss_reta_list_of_items, 1282 NULL, 1283 }, 1284 }; 1285 1286 /* *** SHOW PORT RETA INFO *** */ 1287 struct cmd_showport_reta { 1288 cmdline_fixed_string_t show; 1289 cmdline_fixed_string_t port; 1290 uint8_t port_id; 1291 cmdline_fixed_string_t rss; 1292 cmdline_fixed_string_t reta; 1293 uint64_t mask_lo; 1294 uint64_t mask_hi; 1295 }; 1296 1297 static void cmd_showport_reta_parsed(void *parsed_result, 1298 __attribute__((unused)) struct cmdline *cl, 1299 __attribute__((unused)) void *data) 1300 { 1301 struct cmd_showport_reta *res = parsed_result; 1302 struct rte_eth_rss_reta reta_conf; 1303 1304 if ((res->mask_lo == 0) && (res->mask_hi == 0)) { 1305 printf("Invalid RSS Redirection Table config entered\n"); 1306 return; 1307 } 1308 1309 reta_conf.mask_lo = res->mask_lo; 1310 reta_conf.mask_hi = res->mask_hi; 1311 1312 port_rss_reta_info(res->port_id,&reta_conf); 1313 } 1314 1315 cmdline_parse_token_string_t cmd_showport_reta_show = 1316 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, show, "show"); 1317 cmdline_parse_token_string_t cmd_showport_reta_port = 1318 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, port, "port"); 1319 cmdline_parse_token_num_t cmd_showport_reta_port_id = 1320 TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8); 1321 cmdline_parse_token_string_t cmd_showport_reta_rss = 1322 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss"); 1323 cmdline_parse_token_string_t cmd_showport_reta_reta = 1324 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta"); 1325 cmdline_parse_token_num_t cmd_showport_reta_mask_lo = 1326 TOKEN_NUM_INITIALIZER(struct cmd_showport_reta,mask_lo,UINT64); 1327 cmdline_parse_token_num_t cmd_showport_reta_mask_hi = 1328 TOKEN_NUM_INITIALIZER(struct cmd_showport_reta,mask_hi,UINT64); 1329 1330 cmdline_parse_inst_t cmd_showport_reta = { 1331 .f = cmd_showport_reta_parsed, 1332 .data = NULL, 1333 .help_str = "show port X rss reta mask_lo mask_hi (X = port number)\n\ 1334 (mask_lo and mask_hi is UINT64)", 1335 .tokens = { 1336 (void *)&cmd_showport_reta_show, 1337 (void *)&cmd_showport_reta_port, 1338 (void *)&cmd_showport_reta_port_id, 1339 (void *)&cmd_showport_reta_rss, 1340 (void *)&cmd_showport_reta_reta, 1341 (void *)&cmd_showport_reta_mask_lo, 1342 (void *)&cmd_showport_reta_mask_hi, 1343 NULL, 1344 }, 1345 }; 1346 1347 /* *** Configure DCB *** */ 1348 struct cmd_config_dcb { 1349 cmdline_fixed_string_t port; 1350 cmdline_fixed_string_t config; 1351 uint8_t port_id; 1352 cmdline_fixed_string_t dcb; 1353 cmdline_fixed_string_t vt; 1354 cmdline_fixed_string_t vt_en; 1355 uint8_t num_tcs; 1356 cmdline_fixed_string_t pfc; 1357 cmdline_fixed_string_t pfc_en; 1358 }; 1359 1360 static void 1361 cmd_config_dcb_parsed(void *parsed_result, 1362 __attribute__((unused)) struct cmdline *cl, 1363 __attribute__((unused)) void *data) 1364 { 1365 struct cmd_config_dcb *res = parsed_result; 1366 struct dcb_config dcb_conf; 1367 portid_t port_id = res->port_id; 1368 struct rte_port *port; 1369 1370 port = &ports[port_id]; 1371 /** Check if the port is not started **/ 1372 if (port->port_status != RTE_PORT_STOPPED) { 1373 printf("Please stop port %d first\n",port_id); 1374 return; 1375 } 1376 1377 dcb_conf.num_tcs = (enum rte_eth_nb_tcs) res->num_tcs; 1378 if ((dcb_conf.num_tcs != ETH_4_TCS) && (dcb_conf.num_tcs != ETH_8_TCS)){ 1379 printf("The invalid number of traffic class,only 4 or 8 allowed\n"); 1380 return; 1381 } 1382 1383 /* DCB in VT mode */ 1384 if (!strncmp(res->vt_en, "on",2)) 1385 dcb_conf.dcb_mode = DCB_VT_ENABLED; 1386 else 1387 dcb_conf.dcb_mode = DCB_ENABLED; 1388 1389 if (!strncmp(res->pfc_en, "on",2)) { 1390 dcb_conf.pfc_en = 1; 1391 } 1392 else 1393 dcb_conf.pfc_en = 0; 1394 1395 if (init_port_dcb_config(port_id,&dcb_conf) != 0) { 1396 printf("Cannot initialize network ports\n"); 1397 return; 1398 } 1399 1400 cmd_reconfig_device_queue(port_id, 1, 1); 1401 } 1402 1403 cmdline_parse_token_string_t cmd_config_dcb_port = 1404 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port"); 1405 cmdline_parse_token_string_t cmd_config_dcb_config = 1406 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config"); 1407 cmdline_parse_token_num_t cmd_config_dcb_port_id = 1408 TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8); 1409 cmdline_parse_token_string_t cmd_config_dcb_dcb = 1410 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb"); 1411 cmdline_parse_token_string_t cmd_config_dcb_vt = 1412 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt"); 1413 cmdline_parse_token_string_t cmd_config_dcb_vt_en = 1414 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off"); 1415 cmdline_parse_token_num_t cmd_config_dcb_num_tcs = 1416 TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8); 1417 cmdline_parse_token_string_t cmd_config_dcb_pfc= 1418 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc"); 1419 cmdline_parse_token_string_t cmd_config_dcb_pfc_en = 1420 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off"); 1421 1422 cmdline_parse_inst_t cmd_config_dcb = { 1423 .f = cmd_config_dcb_parsed, 1424 .data = NULL, 1425 .help_str = "port config port-id dcb vt on|off nb-tcs pfc on|off", 1426 .tokens = { 1427 (void *)&cmd_config_dcb_port, 1428 (void *)&cmd_config_dcb_config, 1429 (void *)&cmd_config_dcb_port_id, 1430 (void *)&cmd_config_dcb_dcb, 1431 (void *)&cmd_config_dcb_vt, 1432 (void *)&cmd_config_dcb_vt_en, 1433 (void *)&cmd_config_dcb_num_tcs, 1434 (void *)&cmd_config_dcb_pfc, 1435 (void *)&cmd_config_dcb_pfc_en, 1436 NULL, 1437 }, 1438 }; 1439 1440 /* *** configure number of packets per burst *** */ 1441 struct cmd_config_burst { 1442 cmdline_fixed_string_t port; 1443 cmdline_fixed_string_t keyword; 1444 cmdline_fixed_string_t all; 1445 cmdline_fixed_string_t name; 1446 uint16_t value; 1447 }; 1448 1449 static void 1450 cmd_config_burst_parsed(void *parsed_result, 1451 __attribute__((unused)) struct cmdline *cl, 1452 __attribute__((unused)) void *data) 1453 { 1454 struct cmd_config_burst *res = parsed_result; 1455 1456 if (!all_ports_stopped()) { 1457 printf("Please stop all ports first\n"); 1458 return; 1459 } 1460 1461 if (!strcmp(res->name, "burst")) { 1462 if (res->value < 1 || res->value > MAX_PKT_BURST) { 1463 printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST); 1464 return; 1465 } 1466 nb_pkt_per_burst = res->value; 1467 } else { 1468 printf("Unknown parameter\n"); 1469 return; 1470 } 1471 1472 init_port_config(); 1473 1474 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1475 } 1476 1477 cmdline_parse_token_string_t cmd_config_burst_port = 1478 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port"); 1479 cmdline_parse_token_string_t cmd_config_burst_keyword = 1480 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config"); 1481 cmdline_parse_token_string_t cmd_config_burst_all = 1482 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all"); 1483 cmdline_parse_token_string_t cmd_config_burst_name = 1484 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst"); 1485 cmdline_parse_token_num_t cmd_config_burst_value = 1486 TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16); 1487 1488 cmdline_parse_inst_t cmd_config_burst = { 1489 .f = cmd_config_burst_parsed, 1490 .data = NULL, 1491 .help_str = "port config all burst value", 1492 .tokens = { 1493 (void *)&cmd_config_burst_port, 1494 (void *)&cmd_config_burst_keyword, 1495 (void *)&cmd_config_burst_all, 1496 (void *)&cmd_config_burst_name, 1497 (void *)&cmd_config_burst_value, 1498 NULL, 1499 }, 1500 }; 1501 1502 /* *** configure rx/tx queues *** */ 1503 struct cmd_config_thresh { 1504 cmdline_fixed_string_t port; 1505 cmdline_fixed_string_t keyword; 1506 cmdline_fixed_string_t all; 1507 cmdline_fixed_string_t name; 1508 uint8_t value; 1509 }; 1510 1511 static void 1512 cmd_config_thresh_parsed(void *parsed_result, 1513 __attribute__((unused)) struct cmdline *cl, 1514 __attribute__((unused)) void *data) 1515 { 1516 struct cmd_config_thresh *res = parsed_result; 1517 1518 if (!all_ports_stopped()) { 1519 printf("Please stop all ports first\n"); 1520 return; 1521 } 1522 1523 if (!strcmp(res->name, "txpt")) 1524 tx_thresh.pthresh = res->value; 1525 else if(!strcmp(res->name, "txht")) 1526 tx_thresh.hthresh = res->value; 1527 else if(!strcmp(res->name, "txwt")) 1528 tx_thresh.wthresh = res->value; 1529 else if(!strcmp(res->name, "rxpt")) 1530 rx_thresh.pthresh = res->value; 1531 else if(!strcmp(res->name, "rxht")) 1532 rx_thresh.hthresh = res->value; 1533 else if(!strcmp(res->name, "rxwt")) 1534 rx_thresh.wthresh = res->value; 1535 else { 1536 printf("Unknown parameter\n"); 1537 return; 1538 } 1539 1540 init_port_config(); 1541 1542 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1543 } 1544 1545 cmdline_parse_token_string_t cmd_config_thresh_port = 1546 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port"); 1547 cmdline_parse_token_string_t cmd_config_thresh_keyword = 1548 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config"); 1549 cmdline_parse_token_string_t cmd_config_thresh_all = 1550 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all"); 1551 cmdline_parse_token_string_t cmd_config_thresh_name = 1552 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name, 1553 "txpt#txht#txwt#rxpt#rxht#rxwt"); 1554 cmdline_parse_token_num_t cmd_config_thresh_value = 1555 TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8); 1556 1557 cmdline_parse_inst_t cmd_config_thresh = { 1558 .f = cmd_config_thresh_parsed, 1559 .data = NULL, 1560 .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt value", 1561 .tokens = { 1562 (void *)&cmd_config_thresh_port, 1563 (void *)&cmd_config_thresh_keyword, 1564 (void *)&cmd_config_thresh_all, 1565 (void *)&cmd_config_thresh_name, 1566 (void *)&cmd_config_thresh_value, 1567 NULL, 1568 }, 1569 }; 1570 1571 /* *** configure free/rs threshold *** */ 1572 struct cmd_config_threshold { 1573 cmdline_fixed_string_t port; 1574 cmdline_fixed_string_t keyword; 1575 cmdline_fixed_string_t all; 1576 cmdline_fixed_string_t name; 1577 uint16_t value; 1578 }; 1579 1580 static void 1581 cmd_config_threshold_parsed(void *parsed_result, 1582 __attribute__((unused)) struct cmdline *cl, 1583 __attribute__((unused)) void *data) 1584 { 1585 struct cmd_config_threshold *res = parsed_result; 1586 1587 if (!all_ports_stopped()) { 1588 printf("Please stop all ports first\n"); 1589 return; 1590 } 1591 1592 if (!strcmp(res->name, "txfreet")) 1593 tx_free_thresh = res->value; 1594 else if (!strcmp(res->name, "txrst")) 1595 tx_rs_thresh = res->value; 1596 else if (!strcmp(res->name, "rxfreet")) 1597 rx_free_thresh = res->value; 1598 else { 1599 printf("Unknown parameter\n"); 1600 return; 1601 } 1602 1603 init_port_config(); 1604 1605 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1606 } 1607 1608 cmdline_parse_token_string_t cmd_config_threshold_port = 1609 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port"); 1610 cmdline_parse_token_string_t cmd_config_threshold_keyword = 1611 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword, 1612 "config"); 1613 cmdline_parse_token_string_t cmd_config_threshold_all = 1614 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all"); 1615 cmdline_parse_token_string_t cmd_config_threshold_name = 1616 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name, 1617 "txfreet#txrst#rxfreet"); 1618 cmdline_parse_token_num_t cmd_config_threshold_value = 1619 TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16); 1620 1621 cmdline_parse_inst_t cmd_config_threshold = { 1622 .f = cmd_config_threshold_parsed, 1623 .data = NULL, 1624 .help_str = "port config all txfreet|txrst|rxfreet value", 1625 .tokens = { 1626 (void *)&cmd_config_threshold_port, 1627 (void *)&cmd_config_threshold_keyword, 1628 (void *)&cmd_config_threshold_all, 1629 (void *)&cmd_config_threshold_name, 1630 (void *)&cmd_config_threshold_value, 1631 NULL, 1632 }, 1633 }; 1634 1635 /* *** stop *** */ 1636 struct cmd_stop_result { 1637 cmdline_fixed_string_t stop; 1638 }; 1639 1640 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result, 1641 __attribute__((unused)) struct cmdline *cl, 1642 __attribute__((unused)) void *data) 1643 { 1644 stop_packet_forwarding(); 1645 } 1646 1647 cmdline_parse_token_string_t cmd_stop_stop = 1648 TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop"); 1649 1650 cmdline_parse_inst_t cmd_stop = { 1651 .f = cmd_stop_parsed, 1652 .data = NULL, 1653 .help_str = "stop - stop packet forwarding", 1654 .tokens = { 1655 (void *)&cmd_stop_stop, 1656 NULL, 1657 }, 1658 }; 1659 1660 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */ 1661 1662 static unsigned int 1663 parse_item_list(char* str, const char* item_name, unsigned int max_items, 1664 unsigned int *parsed_items, int check_unique_values) 1665 { 1666 unsigned int nb_item; 1667 unsigned int value; 1668 unsigned int i; 1669 unsigned int j; 1670 int value_ok; 1671 char c; 1672 1673 /* 1674 * First parse all items in the list and store their value. 1675 */ 1676 value = 0; 1677 nb_item = 0; 1678 value_ok = 0; 1679 for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) { 1680 c = str[i]; 1681 if ((c >= '0') && (c <= '9')) { 1682 value = (unsigned int) (value * 10 + (c - '0')); 1683 value_ok = 1; 1684 continue; 1685 } 1686 if (c != ',') { 1687 printf("character %c is not a decimal digit\n", c); 1688 return (0); 1689 } 1690 if (! value_ok) { 1691 printf("No valid value before comma\n"); 1692 return (0); 1693 } 1694 if (nb_item < max_items) { 1695 parsed_items[nb_item] = value; 1696 value_ok = 0; 1697 value = 0; 1698 } 1699 nb_item++; 1700 } 1701 if (nb_item >= max_items) { 1702 printf("Number of %s = %u > %u (maximum items)\n", 1703 item_name, nb_item + 1, max_items); 1704 return (0); 1705 } 1706 parsed_items[nb_item++] = value; 1707 if (! check_unique_values) 1708 return (nb_item); 1709 1710 /* 1711 * Then, check that all values in the list are differents. 1712 * No optimization here... 1713 */ 1714 for (i = 0; i < nb_item; i++) { 1715 for (j = i + 1; j < nb_item; j++) { 1716 if (parsed_items[j] == parsed_items[i]) { 1717 printf("duplicated %s %u at index %u and %u\n", 1718 item_name, parsed_items[i], i, j); 1719 return (0); 1720 } 1721 } 1722 } 1723 return (nb_item); 1724 } 1725 1726 struct cmd_set_list_result { 1727 cmdline_fixed_string_t cmd_keyword; 1728 cmdline_fixed_string_t list_name; 1729 cmdline_fixed_string_t list_of_items; 1730 }; 1731 1732 static void cmd_set_list_parsed(void *parsed_result, 1733 __attribute__((unused)) struct cmdline *cl, 1734 __attribute__((unused)) void *data) 1735 { 1736 struct cmd_set_list_result *res; 1737 union { 1738 unsigned int lcorelist[RTE_MAX_LCORE]; 1739 unsigned int portlist[RTE_MAX_ETHPORTS]; 1740 } parsed_items; 1741 unsigned int nb_item; 1742 1743 res = parsed_result; 1744 if (!strcmp(res->list_name, "corelist")) { 1745 nb_item = parse_item_list(res->list_of_items, "core", 1746 RTE_MAX_LCORE, 1747 parsed_items.lcorelist, 1); 1748 if (nb_item > 0) 1749 set_fwd_lcores_list(parsed_items.lcorelist, nb_item); 1750 return; 1751 } 1752 if (!strcmp(res->list_name, "portlist")) { 1753 nb_item = parse_item_list(res->list_of_items, "port", 1754 RTE_MAX_ETHPORTS, 1755 parsed_items.portlist, 1); 1756 if (nb_item > 0) 1757 set_fwd_ports_list(parsed_items.portlist, nb_item); 1758 } 1759 } 1760 1761 cmdline_parse_token_string_t cmd_set_list_keyword = 1762 TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword, 1763 "set"); 1764 cmdline_parse_token_string_t cmd_set_list_name = 1765 TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name, 1766 "corelist#portlist"); 1767 cmdline_parse_token_string_t cmd_set_list_of_items = 1768 TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items, 1769 NULL); 1770 1771 cmdline_parse_inst_t cmd_set_fwd_list = { 1772 .f = cmd_set_list_parsed, 1773 .data = NULL, 1774 .help_str = "set corelist|portlist x[,y]*", 1775 .tokens = { 1776 (void *)&cmd_set_list_keyword, 1777 (void *)&cmd_set_list_name, 1778 (void *)&cmd_set_list_of_items, 1779 NULL, 1780 }, 1781 }; 1782 1783 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */ 1784 1785 struct cmd_setmask_result { 1786 cmdline_fixed_string_t set; 1787 cmdline_fixed_string_t mask; 1788 uint64_t hexavalue; 1789 }; 1790 1791 static void cmd_set_mask_parsed(void *parsed_result, 1792 __attribute__((unused)) struct cmdline *cl, 1793 __attribute__((unused)) void *data) 1794 { 1795 struct cmd_setmask_result *res = parsed_result; 1796 1797 if (!strcmp(res->mask, "coremask")) 1798 set_fwd_lcores_mask(res->hexavalue); 1799 else if (!strcmp(res->mask, "portmask")) 1800 set_fwd_ports_mask(res->hexavalue); 1801 } 1802 1803 cmdline_parse_token_string_t cmd_setmask_set = 1804 TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set"); 1805 cmdline_parse_token_string_t cmd_setmask_mask = 1806 TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask, 1807 "coremask#portmask"); 1808 cmdline_parse_token_num_t cmd_setmask_value = 1809 TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64); 1810 1811 cmdline_parse_inst_t cmd_set_fwd_mask = { 1812 .f = cmd_set_mask_parsed, 1813 .data = NULL, 1814 .help_str = "set coremask|portmask hexadecimal value", 1815 .tokens = { 1816 (void *)&cmd_setmask_set, 1817 (void *)&cmd_setmask_mask, 1818 (void *)&cmd_setmask_value, 1819 NULL, 1820 }, 1821 }; 1822 1823 /* 1824 * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION 1825 */ 1826 struct cmd_set_result { 1827 cmdline_fixed_string_t set; 1828 cmdline_fixed_string_t what; 1829 uint16_t value; 1830 }; 1831 1832 static void cmd_set_parsed(void *parsed_result, 1833 __attribute__((unused)) struct cmdline *cl, 1834 __attribute__((unused)) void *data) 1835 { 1836 struct cmd_set_result *res = parsed_result; 1837 if (!strcmp(res->what, "nbport")) 1838 set_fwd_ports_number(res->value); 1839 else if (!strcmp(res->what, "nbcore")) 1840 set_fwd_lcores_number(res->value); 1841 else if (!strcmp(res->what, "burst")) 1842 set_nb_pkt_per_burst(res->value); 1843 else if (!strcmp(res->what, "verbose")) 1844 set_verbose_level(res->value); 1845 } 1846 1847 cmdline_parse_token_string_t cmd_set_set = 1848 TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set"); 1849 cmdline_parse_token_string_t cmd_set_what = 1850 TOKEN_STRING_INITIALIZER(struct cmd_set_result, what, 1851 "nbport#nbcore#burst#verbose"); 1852 cmdline_parse_token_num_t cmd_set_value = 1853 TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16); 1854 1855 cmdline_parse_inst_t cmd_set_numbers = { 1856 .f = cmd_set_parsed, 1857 .data = NULL, 1858 .help_str = "set nbport|nbcore|burst|verbose value", 1859 .tokens = { 1860 (void *)&cmd_set_set, 1861 (void *)&cmd_set_what, 1862 (void *)&cmd_set_value, 1863 NULL, 1864 }, 1865 }; 1866 1867 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */ 1868 1869 struct cmd_set_txpkts_result { 1870 cmdline_fixed_string_t cmd_keyword; 1871 cmdline_fixed_string_t txpkts; 1872 cmdline_fixed_string_t seg_lengths; 1873 }; 1874 1875 static void 1876 cmd_set_txpkts_parsed(void *parsed_result, 1877 __attribute__((unused)) struct cmdline *cl, 1878 __attribute__((unused)) void *data) 1879 { 1880 struct cmd_set_txpkts_result *res; 1881 unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT]; 1882 unsigned int nb_segs; 1883 1884 res = parsed_result; 1885 nb_segs = parse_item_list(res->seg_lengths, "segment lengths", 1886 RTE_MAX_SEGS_PER_PKT, seg_lengths, 0); 1887 if (nb_segs > 0) 1888 set_tx_pkt_segments(seg_lengths, nb_segs); 1889 } 1890 1891 cmdline_parse_token_string_t cmd_set_txpkts_keyword = 1892 TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result, 1893 cmd_keyword, "set"); 1894 cmdline_parse_token_string_t cmd_set_txpkts_name = 1895 TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result, 1896 txpkts, "txpkts"); 1897 cmdline_parse_token_string_t cmd_set_txpkts_lengths = 1898 TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result, 1899 seg_lengths, NULL); 1900 1901 cmdline_parse_inst_t cmd_set_txpkts = { 1902 .f = cmd_set_txpkts_parsed, 1903 .data = NULL, 1904 .help_str = "set txpkts x[,y]*", 1905 .tokens = { 1906 (void *)&cmd_set_txpkts_keyword, 1907 (void *)&cmd_set_txpkts_name, 1908 (void *)&cmd_set_txpkts_lengths, 1909 NULL, 1910 }, 1911 }; 1912 1913 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */ 1914 struct cmd_rx_vlan_filter_all_result { 1915 cmdline_fixed_string_t rx_vlan; 1916 cmdline_fixed_string_t what; 1917 cmdline_fixed_string_t all; 1918 uint8_t port_id; 1919 }; 1920 1921 static void 1922 cmd_rx_vlan_filter_all_parsed(void *parsed_result, 1923 __attribute__((unused)) struct cmdline *cl, 1924 __attribute__((unused)) void *data) 1925 { 1926 struct cmd_rx_vlan_filter_all_result *res = parsed_result; 1927 1928 if (!strcmp(res->what, "add")) 1929 rx_vlan_all_filter_set(res->port_id, 1); 1930 else 1931 rx_vlan_all_filter_set(res->port_id, 0); 1932 } 1933 1934 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan = 1935 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 1936 rx_vlan, "rx_vlan"); 1937 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what = 1938 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 1939 what, "add#rm"); 1940 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all = 1941 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 1942 all, "all"); 1943 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid = 1944 TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 1945 port_id, UINT8); 1946 1947 cmdline_parse_inst_t cmd_rx_vlan_filter_all = { 1948 .f = cmd_rx_vlan_filter_all_parsed, 1949 .data = NULL, 1950 .help_str = "add/remove all identifiers to/from the set of VLAN " 1951 "Identifiers filtered by a port", 1952 .tokens = { 1953 (void *)&cmd_rx_vlan_filter_all_rx_vlan, 1954 (void *)&cmd_rx_vlan_filter_all_what, 1955 (void *)&cmd_rx_vlan_filter_all_all, 1956 (void *)&cmd_rx_vlan_filter_all_portid, 1957 NULL, 1958 }, 1959 }; 1960 1961 /* *** VLAN OFFLOAD SET ON A PORT *** */ 1962 struct cmd_vlan_offload_result { 1963 cmdline_fixed_string_t vlan; 1964 cmdline_fixed_string_t set; 1965 cmdline_fixed_string_t what; 1966 cmdline_fixed_string_t on; 1967 cmdline_fixed_string_t port_id; 1968 }; 1969 1970 static void 1971 cmd_vlan_offload_parsed(void *parsed_result, 1972 __attribute__((unused)) struct cmdline *cl, 1973 __attribute__((unused)) void *data) 1974 { 1975 int on; 1976 struct cmd_vlan_offload_result *res = parsed_result; 1977 char *str; 1978 int i, len = 0; 1979 portid_t port_id = 0; 1980 unsigned int tmp; 1981 1982 str = res->port_id; 1983 len = strnlen(str, STR_TOKEN_SIZE); 1984 i = 0; 1985 /* Get port_id first */ 1986 while(i < len){ 1987 if(str[i] == ',') 1988 break; 1989 1990 i++; 1991 } 1992 str[i]='\0'; 1993 tmp = strtoul(str, NULL, 0); 1994 /* If port_id greater that what portid_t can represent, return */ 1995 if(tmp >= RTE_MAX_ETHPORTS) 1996 return; 1997 port_id = (portid_t)tmp; 1998 1999 if (!strcmp(res->on, "on")) 2000 on = 1; 2001 else 2002 on = 0; 2003 2004 if (!strcmp(res->what, "strip")) 2005 rx_vlan_strip_set(port_id, on); 2006 else if(!strcmp(res->what, "stripq")){ 2007 uint16_t queue_id = 0; 2008 2009 /* No queue_id, return */ 2010 if(i + 1 >= len) { 2011 printf("must specify (port,queue_id)\n"); 2012 return; 2013 } 2014 tmp = strtoul(str + i + 1, NULL, 0); 2015 /* If queue_id greater that what 16-bits can represent, return */ 2016 if(tmp > 0xffff) 2017 return; 2018 2019 queue_id = (uint16_t)tmp; 2020 rx_vlan_strip_set_on_queue(port_id, queue_id, on); 2021 } 2022 else if (!strcmp(res->what, "filter")) 2023 rx_vlan_filter_set(port_id, on); 2024 else 2025 vlan_extend_set(port_id, on); 2026 2027 return; 2028 } 2029 2030 cmdline_parse_token_string_t cmd_vlan_offload_vlan = 2031 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 2032 vlan, "vlan"); 2033 cmdline_parse_token_string_t cmd_vlan_offload_set = 2034 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 2035 set, "set"); 2036 cmdline_parse_token_string_t cmd_vlan_offload_what = 2037 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 2038 what, "strip#filter#qinq#stripq"); 2039 cmdline_parse_token_string_t cmd_vlan_offload_on = 2040 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 2041 on, "on#off"); 2042 cmdline_parse_token_string_t cmd_vlan_offload_portid = 2043 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 2044 port_id, NULL); 2045 2046 cmdline_parse_inst_t cmd_vlan_offload = { 2047 .f = cmd_vlan_offload_parsed, 2048 .data = NULL, 2049 .help_str = "set strip|filter|qinq|stripq on|off port_id[,queue_id], filter/strip for rx side" 2050 " qinq(extended) for both rx/tx sides ", 2051 .tokens = { 2052 (void *)&cmd_vlan_offload_vlan, 2053 (void *)&cmd_vlan_offload_set, 2054 (void *)&cmd_vlan_offload_what, 2055 (void *)&cmd_vlan_offload_on, 2056 (void *)&cmd_vlan_offload_portid, 2057 NULL, 2058 }, 2059 }; 2060 2061 /* *** VLAN TPID SET ON A PORT *** */ 2062 struct cmd_vlan_tpid_result { 2063 cmdline_fixed_string_t vlan; 2064 cmdline_fixed_string_t set; 2065 cmdline_fixed_string_t what; 2066 uint16_t tp_id; 2067 uint8_t port_id; 2068 }; 2069 2070 static void 2071 cmd_vlan_tpid_parsed(void *parsed_result, 2072 __attribute__((unused)) struct cmdline *cl, 2073 __attribute__((unused)) void *data) 2074 { 2075 struct cmd_vlan_tpid_result *res = parsed_result; 2076 vlan_tpid_set(res->port_id, res->tp_id); 2077 return; 2078 } 2079 2080 cmdline_parse_token_string_t cmd_vlan_tpid_vlan = 2081 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 2082 vlan, "vlan"); 2083 cmdline_parse_token_string_t cmd_vlan_tpid_set = 2084 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 2085 set, "set"); 2086 cmdline_parse_token_string_t cmd_vlan_tpid_what = 2087 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 2088 what, "tpid"); 2089 cmdline_parse_token_num_t cmd_vlan_tpid_tpid = 2090 TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result, 2091 tp_id, UINT16); 2092 cmdline_parse_token_num_t cmd_vlan_tpid_portid = 2093 TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result, 2094 port_id, UINT8); 2095 2096 cmdline_parse_inst_t cmd_vlan_tpid = { 2097 .f = cmd_vlan_tpid_parsed, 2098 .data = NULL, 2099 .help_str = "set tpid tp_id port_id, set the Outer VLAN Ether type", 2100 .tokens = { 2101 (void *)&cmd_vlan_tpid_vlan, 2102 (void *)&cmd_vlan_tpid_set, 2103 (void *)&cmd_vlan_tpid_what, 2104 (void *)&cmd_vlan_tpid_tpid, 2105 (void *)&cmd_vlan_tpid_portid, 2106 NULL, 2107 }, 2108 }; 2109 2110 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */ 2111 struct cmd_rx_vlan_filter_result { 2112 cmdline_fixed_string_t rx_vlan; 2113 cmdline_fixed_string_t what; 2114 uint16_t vlan_id; 2115 uint8_t port_id; 2116 }; 2117 2118 static void 2119 cmd_rx_vlan_filter_parsed(void *parsed_result, 2120 __attribute__((unused)) struct cmdline *cl, 2121 __attribute__((unused)) void *data) 2122 { 2123 struct cmd_rx_vlan_filter_result *res = parsed_result; 2124 2125 if (!strcmp(res->what, "add")) 2126 rx_vft_set(res->port_id, res->vlan_id, 1); 2127 else 2128 rx_vft_set(res->port_id, res->vlan_id, 0); 2129 } 2130 2131 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan = 2132 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result, 2133 rx_vlan, "rx_vlan"); 2134 cmdline_parse_token_string_t cmd_rx_vlan_filter_what = 2135 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result, 2136 what, "add#rm"); 2137 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid = 2138 TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result, 2139 vlan_id, UINT16); 2140 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid = 2141 TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result, 2142 port_id, UINT8); 2143 2144 cmdline_parse_inst_t cmd_rx_vlan_filter = { 2145 .f = cmd_rx_vlan_filter_parsed, 2146 .data = NULL, 2147 .help_str = "add/remove a VLAN identifier to/from the set of VLAN " 2148 "Identifiers filtered by a port", 2149 .tokens = { 2150 (void *)&cmd_rx_vlan_filter_rx_vlan, 2151 (void *)&cmd_rx_vlan_filter_what, 2152 (void *)&cmd_rx_vlan_filter_vlanid, 2153 (void *)&cmd_rx_vlan_filter_portid, 2154 NULL, 2155 }, 2156 }; 2157 2158 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */ 2159 struct cmd_tx_vlan_set_result { 2160 cmdline_fixed_string_t tx_vlan; 2161 cmdline_fixed_string_t set; 2162 uint16_t vlan_id; 2163 uint8_t port_id; 2164 }; 2165 2166 static void 2167 cmd_tx_vlan_set_parsed(void *parsed_result, 2168 __attribute__((unused)) struct cmdline *cl, 2169 __attribute__((unused)) void *data) 2170 { 2171 struct cmd_tx_vlan_set_result *res = parsed_result; 2172 tx_vlan_set(res->port_id, res->vlan_id); 2173 } 2174 2175 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan = 2176 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result, 2177 tx_vlan, "tx_vlan"); 2178 cmdline_parse_token_string_t cmd_tx_vlan_set_set = 2179 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result, 2180 set, "set"); 2181 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid = 2182 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result, 2183 vlan_id, UINT16); 2184 cmdline_parse_token_num_t cmd_tx_vlan_set_portid = 2185 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result, 2186 port_id, UINT8); 2187 2188 cmdline_parse_inst_t cmd_tx_vlan_set = { 2189 .f = cmd_tx_vlan_set_parsed, 2190 .data = NULL, 2191 .help_str = "enable hardware insertion of a VLAN header with a given " 2192 "TAG Identifier in packets sent on a port", 2193 .tokens = { 2194 (void *)&cmd_tx_vlan_set_tx_vlan, 2195 (void *)&cmd_tx_vlan_set_set, 2196 (void *)&cmd_tx_vlan_set_vlanid, 2197 (void *)&cmd_tx_vlan_set_portid, 2198 NULL, 2199 }, 2200 }; 2201 2202 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */ 2203 struct cmd_tx_vlan_reset_result { 2204 cmdline_fixed_string_t tx_vlan; 2205 cmdline_fixed_string_t reset; 2206 uint8_t port_id; 2207 }; 2208 2209 static void 2210 cmd_tx_vlan_reset_parsed(void *parsed_result, 2211 __attribute__((unused)) struct cmdline *cl, 2212 __attribute__((unused)) void *data) 2213 { 2214 struct cmd_tx_vlan_reset_result *res = parsed_result; 2215 2216 tx_vlan_reset(res->port_id); 2217 } 2218 2219 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan = 2220 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result, 2221 tx_vlan, "tx_vlan"); 2222 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset = 2223 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result, 2224 reset, "reset"); 2225 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid = 2226 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result, 2227 port_id, UINT8); 2228 2229 cmdline_parse_inst_t cmd_tx_vlan_reset = { 2230 .f = cmd_tx_vlan_reset_parsed, 2231 .data = NULL, 2232 .help_str = "disable hardware insertion of a VLAN header in packets " 2233 "sent on a port", 2234 .tokens = { 2235 (void *)&cmd_tx_vlan_reset_tx_vlan, 2236 (void *)&cmd_tx_vlan_reset_reset, 2237 (void *)&cmd_tx_vlan_reset_portid, 2238 NULL, 2239 }, 2240 }; 2241 2242 2243 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */ 2244 struct cmd_tx_cksum_set_result { 2245 cmdline_fixed_string_t tx_cksum; 2246 cmdline_fixed_string_t set; 2247 uint8_t cksum_mask; 2248 uint8_t port_id; 2249 }; 2250 2251 static void 2252 cmd_tx_cksum_set_parsed(void *parsed_result, 2253 __attribute__((unused)) struct cmdline *cl, 2254 __attribute__((unused)) void *data) 2255 { 2256 struct cmd_tx_cksum_set_result *res = parsed_result; 2257 2258 tx_cksum_set(res->port_id, res->cksum_mask); 2259 } 2260 2261 cmdline_parse_token_string_t cmd_tx_cksum_set_tx_cksum = 2262 TOKEN_STRING_INITIALIZER(struct cmd_tx_cksum_set_result, 2263 tx_cksum, "tx_checksum"); 2264 cmdline_parse_token_string_t cmd_tx_cksum_set_set = 2265 TOKEN_STRING_INITIALIZER(struct cmd_tx_cksum_set_result, 2266 set, "set"); 2267 cmdline_parse_token_num_t cmd_tx_cksum_set_cksum_mask = 2268 TOKEN_NUM_INITIALIZER(struct cmd_tx_cksum_set_result, 2269 cksum_mask, UINT8); 2270 cmdline_parse_token_num_t cmd_tx_cksum_set_portid = 2271 TOKEN_NUM_INITIALIZER(struct cmd_tx_cksum_set_result, 2272 port_id, UINT8); 2273 2274 cmdline_parse_inst_t cmd_tx_cksum_set = { 2275 .f = cmd_tx_cksum_set_parsed, 2276 .data = NULL, 2277 .help_str = "enable hardware insertion of L3/L4checksum with a given " 2278 "mask in packets sent on a port, the bit mapping is given as, Bit 0 for ip" 2279 "Bit 1 for UDP, Bit 2 for TCP, Bit 3 for SCTP", 2280 .tokens = { 2281 (void *)&cmd_tx_cksum_set_tx_cksum, 2282 (void *)&cmd_tx_cksum_set_set, 2283 (void *)&cmd_tx_cksum_set_cksum_mask, 2284 (void *)&cmd_tx_cksum_set_portid, 2285 NULL, 2286 }, 2287 }; 2288 2289 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */ 2290 struct cmd_set_flush_rx { 2291 cmdline_fixed_string_t set; 2292 cmdline_fixed_string_t flush_rx; 2293 cmdline_fixed_string_t mode; 2294 }; 2295 2296 static void 2297 cmd_set_flush_rx_parsed(void *parsed_result, 2298 __attribute__((unused)) struct cmdline *cl, 2299 __attribute__((unused)) void *data) 2300 { 2301 struct cmd_set_flush_rx *res = parsed_result; 2302 no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1); 2303 } 2304 2305 cmdline_parse_token_string_t cmd_setflushrx_set = 2306 TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx, 2307 set, "set"); 2308 cmdline_parse_token_string_t cmd_setflushrx_flush_rx = 2309 TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx, 2310 flush_rx, "flush_rx"); 2311 cmdline_parse_token_string_t cmd_setflushrx_mode = 2312 TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx, 2313 mode, "on#off"); 2314 2315 2316 cmdline_parse_inst_t cmd_set_flush_rx = { 2317 .f = cmd_set_flush_rx_parsed, 2318 .help_str = "set flush_rx on|off: enable/disable flush on rx streams", 2319 .data = NULL, 2320 .tokens = { 2321 (void *)&cmd_setflushrx_set, 2322 (void *)&cmd_setflushrx_flush_rx, 2323 (void *)&cmd_setflushrx_mode, 2324 NULL, 2325 }, 2326 }; 2327 2328 #ifdef RTE_NIC_BYPASS 2329 /* *** SET NIC BYPASS MODE *** */ 2330 struct cmd_set_bypass_mode_result { 2331 cmdline_fixed_string_t set; 2332 cmdline_fixed_string_t bypass; 2333 cmdline_fixed_string_t mode; 2334 cmdline_fixed_string_t value; 2335 uint8_t port_id; 2336 }; 2337 2338 static void 2339 cmd_set_bypass_mode_parsed(void *parsed_result, 2340 __attribute__((unused)) struct cmdline *cl, 2341 __attribute__((unused)) void *data) 2342 { 2343 struct cmd_set_bypass_mode_result *res = parsed_result; 2344 portid_t port_id = res->port_id; 2345 uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL; 2346 2347 if (!bypass_is_supported(port_id)) 2348 return; 2349 2350 if (!strcmp(res->value, "bypass")) 2351 bypass_mode = RTE_BYPASS_MODE_BYPASS; 2352 else if (!strcmp(res->value, "isolate")) 2353 bypass_mode = RTE_BYPASS_MODE_ISOLATE; 2354 else 2355 bypass_mode = RTE_BYPASS_MODE_NORMAL; 2356 2357 /* Set the bypass mode for the relevant port. */ 2358 if (0 != rte_eth_dev_bypass_state_set(port_id, &bypass_mode)) { 2359 printf("\t Failed to set bypass mode for port = %d.\n", port_id); 2360 } 2361 } 2362 2363 cmdline_parse_token_string_t cmd_setbypass_mode_set = 2364 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 2365 set, "set"); 2366 cmdline_parse_token_string_t cmd_setbypass_mode_bypass = 2367 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 2368 bypass, "bypass"); 2369 cmdline_parse_token_string_t cmd_setbypass_mode_mode = 2370 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 2371 mode, "mode"); 2372 cmdline_parse_token_string_t cmd_setbypass_mode_value = 2373 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 2374 value, "normal#bypass#isolate"); 2375 cmdline_parse_token_num_t cmd_setbypass_mode_port = 2376 TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result, 2377 port_id, UINT8); 2378 2379 cmdline_parse_inst_t cmd_set_bypass_mode = { 2380 .f = cmd_set_bypass_mode_parsed, 2381 .help_str = "set bypass mode (normal|bypass|isolate) (port_id): " 2382 "Set the NIC bypass mode for port_id", 2383 .data = NULL, 2384 .tokens = { 2385 (void *)&cmd_setbypass_mode_set, 2386 (void *)&cmd_setbypass_mode_bypass, 2387 (void *)&cmd_setbypass_mode_mode, 2388 (void *)&cmd_setbypass_mode_value, 2389 (void *)&cmd_setbypass_mode_port, 2390 NULL, 2391 }, 2392 }; 2393 2394 /* *** SET NIC BYPASS EVENT *** */ 2395 struct cmd_set_bypass_event_result { 2396 cmdline_fixed_string_t set; 2397 cmdline_fixed_string_t bypass; 2398 cmdline_fixed_string_t event; 2399 cmdline_fixed_string_t event_value; 2400 cmdline_fixed_string_t mode; 2401 cmdline_fixed_string_t mode_value; 2402 uint8_t port_id; 2403 }; 2404 2405 static void 2406 cmd_set_bypass_event_parsed(void *parsed_result, 2407 __attribute__((unused)) struct cmdline *cl, 2408 __attribute__((unused)) void *data) 2409 { 2410 int32_t rc; 2411 struct cmd_set_bypass_event_result *res = parsed_result; 2412 portid_t port_id = res->port_id; 2413 uint32_t bypass_event = RTE_BYPASS_EVENT_NONE; 2414 uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL; 2415 2416 if (!bypass_is_supported(port_id)) 2417 return; 2418 2419 if (!strcmp(res->event_value, "timeout")) 2420 bypass_event = RTE_BYPASS_EVENT_TIMEOUT; 2421 else if (!strcmp(res->event_value, "os_on")) 2422 bypass_event = RTE_BYPASS_EVENT_OS_ON; 2423 else if (!strcmp(res->event_value, "os_off")) 2424 bypass_event = RTE_BYPASS_EVENT_OS_OFF; 2425 else if (!strcmp(res->event_value, "power_on")) 2426 bypass_event = RTE_BYPASS_EVENT_POWER_ON; 2427 else if (!strcmp(res->event_value, "power_off")) 2428 bypass_event = RTE_BYPASS_EVENT_POWER_OFF; 2429 else 2430 bypass_event = RTE_BYPASS_EVENT_NONE; 2431 2432 if (!strcmp(res->mode_value, "bypass")) 2433 bypass_mode = RTE_BYPASS_MODE_BYPASS; 2434 else if (!strcmp(res->mode_value, "isolate")) 2435 bypass_mode = RTE_BYPASS_MODE_ISOLATE; 2436 else 2437 bypass_mode = RTE_BYPASS_MODE_NORMAL; 2438 2439 /* Set the watchdog timeout. */ 2440 if (bypass_event == RTE_BYPASS_EVENT_TIMEOUT) { 2441 2442 rc = -EINVAL; 2443 if (!RTE_BYPASS_TMT_VALID(bypass_timeout) || 2444 (rc = rte_eth_dev_wd_timeout_store(port_id, 2445 bypass_timeout)) != 0) { 2446 printf("Failed to set timeout value %u " 2447 "for port %d, errto code: %d.\n", 2448 bypass_timeout, port_id, rc); 2449 } 2450 } 2451 2452 /* Set the bypass event to transition to bypass mode. */ 2453 if (0 != rte_eth_dev_bypass_event_store(port_id, 2454 bypass_event, bypass_mode)) { 2455 printf("\t Failed to set bypass event for port = %d.\n", port_id); 2456 } 2457 2458 } 2459 2460 cmdline_parse_token_string_t cmd_setbypass_event_set = 2461 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 2462 set, "set"); 2463 cmdline_parse_token_string_t cmd_setbypass_event_bypass = 2464 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 2465 bypass, "bypass"); 2466 cmdline_parse_token_string_t cmd_setbypass_event_event = 2467 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 2468 event, "event"); 2469 cmdline_parse_token_string_t cmd_setbypass_event_event_value = 2470 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 2471 event_value, "none#timeout#os_off#os_on#power_on#power_off"); 2472 cmdline_parse_token_string_t cmd_setbypass_event_mode = 2473 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 2474 mode, "mode"); 2475 cmdline_parse_token_string_t cmd_setbypass_event_mode_value = 2476 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 2477 mode_value, "normal#bypass#isolate"); 2478 cmdline_parse_token_num_t cmd_setbypass_event_port = 2479 TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result, 2480 port_id, UINT8); 2481 2482 cmdline_parse_inst_t cmd_set_bypass_event = { 2483 .f = cmd_set_bypass_event_parsed, 2484 .help_str = "set bypass event (timeout|os_on|os_off|power_on|power_off) " 2485 "mode (normal|bypass|isolate) (port_id): " 2486 "Set the NIC bypass event mode for port_id", 2487 .data = NULL, 2488 .tokens = { 2489 (void *)&cmd_setbypass_event_set, 2490 (void *)&cmd_setbypass_event_bypass, 2491 (void *)&cmd_setbypass_event_event, 2492 (void *)&cmd_setbypass_event_event_value, 2493 (void *)&cmd_setbypass_event_mode, 2494 (void *)&cmd_setbypass_event_mode_value, 2495 (void *)&cmd_setbypass_event_port, 2496 NULL, 2497 }, 2498 }; 2499 2500 2501 /* *** SET NIC BYPASS TIMEOUT *** */ 2502 struct cmd_set_bypass_timeout_result { 2503 cmdline_fixed_string_t set; 2504 cmdline_fixed_string_t bypass; 2505 cmdline_fixed_string_t timeout; 2506 cmdline_fixed_string_t value; 2507 }; 2508 2509 static void 2510 cmd_set_bypass_timeout_parsed(void *parsed_result, 2511 __attribute__((unused)) struct cmdline *cl, 2512 __attribute__((unused)) void *data) 2513 { 2514 struct cmd_set_bypass_timeout_result *res = parsed_result; 2515 2516 if (!strcmp(res->value, "1.5")) 2517 bypass_timeout = RTE_BYPASS_TMT_1_5_SEC; 2518 else if (!strcmp(res->value, "2")) 2519 bypass_timeout = RTE_BYPASS_TMT_2_SEC; 2520 else if (!strcmp(res->value, "3")) 2521 bypass_timeout = RTE_BYPASS_TMT_3_SEC; 2522 else if (!strcmp(res->value, "4")) 2523 bypass_timeout = RTE_BYPASS_TMT_4_SEC; 2524 else if (!strcmp(res->value, "8")) 2525 bypass_timeout = RTE_BYPASS_TMT_8_SEC; 2526 else if (!strcmp(res->value, "16")) 2527 bypass_timeout = RTE_BYPASS_TMT_16_SEC; 2528 else if (!strcmp(res->value, "32")) 2529 bypass_timeout = RTE_BYPASS_TMT_32_SEC; 2530 else 2531 bypass_timeout = RTE_BYPASS_TMT_OFF; 2532 } 2533 2534 cmdline_parse_token_string_t cmd_setbypass_timeout_set = 2535 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 2536 set, "set"); 2537 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass = 2538 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 2539 bypass, "bypass"); 2540 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout = 2541 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 2542 timeout, "timeout"); 2543 cmdline_parse_token_string_t cmd_setbypass_timeout_value = 2544 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 2545 value, "0#1.5#2#3#4#8#16#32"); 2546 2547 cmdline_parse_inst_t cmd_set_bypass_timeout = { 2548 .f = cmd_set_bypass_timeout_parsed, 2549 .help_str = "set bypass timeout (0|1.5|2|3|4|8|16|32) seconds: " 2550 "Set the NIC bypass watchdog timeout", 2551 .data = NULL, 2552 .tokens = { 2553 (void *)&cmd_setbypass_timeout_set, 2554 (void *)&cmd_setbypass_timeout_bypass, 2555 (void *)&cmd_setbypass_timeout_timeout, 2556 (void *)&cmd_setbypass_timeout_value, 2557 NULL, 2558 }, 2559 }; 2560 2561 /* *** SHOW NIC BYPASS MODE *** */ 2562 struct cmd_show_bypass_config_result { 2563 cmdline_fixed_string_t show; 2564 cmdline_fixed_string_t bypass; 2565 cmdline_fixed_string_t config; 2566 uint8_t port_id; 2567 }; 2568 2569 static void 2570 cmd_show_bypass_config_parsed(void *parsed_result, 2571 __attribute__((unused)) struct cmdline *cl, 2572 __attribute__((unused)) void *data) 2573 { 2574 struct cmd_show_bypass_config_result *res = parsed_result; 2575 uint32_t event_mode; 2576 uint32_t bypass_mode; 2577 portid_t port_id = res->port_id; 2578 uint32_t timeout = bypass_timeout; 2579 int i; 2580 2581 static const char * const timeouts[RTE_BYPASS_TMT_NUM] = 2582 {"off", "1.5", "2", "3", "4", "8", "16", "32"}; 2583 static const char * const modes[RTE_BYPASS_MODE_NUM] = 2584 {"UNKNOWN", "normal", "bypass", "isolate"}; 2585 static const char * const events[RTE_BYPASS_EVENT_NUM] = { 2586 "NONE", 2587 "OS/board on", 2588 "power supply on", 2589 "OS/board off", 2590 "power supply off", 2591 "timeout"}; 2592 int num_events = (sizeof events) / (sizeof events[0]); 2593 2594 if (!bypass_is_supported(port_id)) 2595 return; 2596 2597 /* Display the bypass mode.*/ 2598 if (0 != rte_eth_dev_bypass_state_show(port_id, &bypass_mode)) { 2599 printf("\tFailed to get bypass mode for port = %d\n", port_id); 2600 return; 2601 } 2602 else { 2603 if (!RTE_BYPASS_MODE_VALID(bypass_mode)) 2604 bypass_mode = RTE_BYPASS_MODE_NONE; 2605 2606 printf("\tbypass mode = %s\n", modes[bypass_mode]); 2607 } 2608 2609 /* Display the bypass timeout.*/ 2610 if (!RTE_BYPASS_TMT_VALID(timeout)) 2611 timeout = RTE_BYPASS_TMT_OFF; 2612 2613 printf("\tbypass timeout = %s\n", timeouts[timeout]); 2614 2615 /* Display the bypass events and associated modes. */ 2616 for (i = RTE_BYPASS_EVENT_START; i < num_events; i++) { 2617 2618 if (0 != rte_eth_dev_bypass_event_show(port_id, i, &event_mode)) { 2619 printf("\tFailed to get bypass mode for event = %s\n", 2620 events[i]); 2621 } else { 2622 if (!RTE_BYPASS_MODE_VALID(event_mode)) 2623 event_mode = RTE_BYPASS_MODE_NONE; 2624 2625 printf("\tbypass event: %-16s = %s\n", events[i], 2626 modes[event_mode]); 2627 } 2628 } 2629 } 2630 2631 cmdline_parse_token_string_t cmd_showbypass_config_show = 2632 TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, 2633 show, "show"); 2634 cmdline_parse_token_string_t cmd_showbypass_config_bypass = 2635 TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, 2636 bypass, "bypass"); 2637 cmdline_parse_token_string_t cmd_showbypass_config_config = 2638 TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, 2639 config, "config"); 2640 cmdline_parse_token_num_t cmd_showbypass_config_port = 2641 TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result, 2642 port_id, UINT8); 2643 2644 cmdline_parse_inst_t cmd_show_bypass_config = { 2645 .f = cmd_show_bypass_config_parsed, 2646 .help_str = "show bypass config (port_id): " 2647 "Show the NIC bypass config for port_id", 2648 .data = NULL, 2649 .tokens = { 2650 (void *)&cmd_showbypass_config_show, 2651 (void *)&cmd_showbypass_config_bypass, 2652 (void *)&cmd_showbypass_config_config, 2653 (void *)&cmd_showbypass_config_port, 2654 NULL, 2655 }, 2656 }; 2657 #endif 2658 2659 /* *** SET FORWARDING MODE *** */ 2660 struct cmd_set_fwd_mode_result { 2661 cmdline_fixed_string_t set; 2662 cmdline_fixed_string_t fwd; 2663 cmdline_fixed_string_t mode; 2664 }; 2665 2666 static void cmd_set_fwd_mode_parsed(void *parsed_result, 2667 __attribute__((unused)) struct cmdline *cl, 2668 __attribute__((unused)) void *data) 2669 { 2670 struct cmd_set_fwd_mode_result *res = parsed_result; 2671 2672 set_pkt_forwarding_mode(res->mode); 2673 } 2674 2675 cmdline_parse_token_string_t cmd_setfwd_set = 2676 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set"); 2677 cmdline_parse_token_string_t cmd_setfwd_fwd = 2678 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd"); 2679 cmdline_parse_token_string_t cmd_setfwd_mode = 2680 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode, 2681 #ifdef RTE_LIBRTE_IEEE1588 2682 "io#mac#rxonly#txonly#csum#ieee1588"); 2683 #else 2684 "io#mac#rxonly#txonly#csum"); 2685 #endif 2686 2687 cmdline_parse_inst_t cmd_set_fwd_mode = { 2688 .f = cmd_set_fwd_mode_parsed, 2689 .data = NULL, 2690 #ifdef RTE_LIBRTE_IEEE1588 2691 .help_str = "set fwd io|mac|rxonly|txonly|csum|ieee1588 - set IO, MAC," 2692 " RXONLY, TXONLY, CSUM or IEEE1588 packet forwarding mode", 2693 #else 2694 .help_str = "set fwd io|mac|rxonly|txonly|csum - set IO, MAC," 2695 " RXONLY, CSUM or TXONLY packet forwarding mode", 2696 #endif 2697 .tokens = { 2698 (void *)&cmd_setfwd_set, 2699 (void *)&cmd_setfwd_fwd, 2700 (void *)&cmd_setfwd_mode, 2701 NULL, 2702 }, 2703 }; 2704 2705 /* *** SET PROMISC MODE *** */ 2706 struct cmd_set_promisc_mode_result { 2707 cmdline_fixed_string_t set; 2708 cmdline_fixed_string_t promisc; 2709 cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */ 2710 uint8_t port_num; /* valid if "allports" argument == 0 */ 2711 cmdline_fixed_string_t mode; 2712 }; 2713 2714 static void cmd_set_promisc_mode_parsed(void *parsed_result, 2715 __attribute__((unused)) struct cmdline *cl, 2716 void *allports) 2717 { 2718 struct cmd_set_promisc_mode_result *res = parsed_result; 2719 int enable; 2720 portid_t i; 2721 2722 if (!strcmp(res->mode, "on")) 2723 enable = 1; 2724 else 2725 enable = 0; 2726 2727 /* all ports */ 2728 if (allports) { 2729 for (i = 0; i < nb_ports; i++) { 2730 if (enable) 2731 rte_eth_promiscuous_enable(i); 2732 else 2733 rte_eth_promiscuous_disable(i); 2734 } 2735 } 2736 else { 2737 if (enable) 2738 rte_eth_promiscuous_enable(res->port_num); 2739 else 2740 rte_eth_promiscuous_disable(res->port_num); 2741 } 2742 } 2743 2744 cmdline_parse_token_string_t cmd_setpromisc_set = 2745 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set"); 2746 cmdline_parse_token_string_t cmd_setpromisc_promisc = 2747 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc, 2748 "promisc"); 2749 cmdline_parse_token_string_t cmd_setpromisc_portall = 2750 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all, 2751 "all"); 2752 cmdline_parse_token_num_t cmd_setpromisc_portnum = 2753 TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num, 2754 UINT8); 2755 cmdline_parse_token_string_t cmd_setpromisc_mode = 2756 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode, 2757 "on#off"); 2758 2759 cmdline_parse_inst_t cmd_set_promisc_mode_all = { 2760 .f = cmd_set_promisc_mode_parsed, 2761 .data = (void *)1, 2762 .help_str = "set promisc all on|off: set promisc mode for all ports", 2763 .tokens = { 2764 (void *)&cmd_setpromisc_set, 2765 (void *)&cmd_setpromisc_promisc, 2766 (void *)&cmd_setpromisc_portall, 2767 (void *)&cmd_setpromisc_mode, 2768 NULL, 2769 }, 2770 }; 2771 2772 cmdline_parse_inst_t cmd_set_promisc_mode_one = { 2773 .f = cmd_set_promisc_mode_parsed, 2774 .data = (void *)0, 2775 .help_str = "set promisc X on|off: set promisc mode on port X", 2776 .tokens = { 2777 (void *)&cmd_setpromisc_set, 2778 (void *)&cmd_setpromisc_promisc, 2779 (void *)&cmd_setpromisc_portnum, 2780 (void *)&cmd_setpromisc_mode, 2781 NULL, 2782 }, 2783 }; 2784 2785 /* *** SET ALLMULTI MODE *** */ 2786 struct cmd_set_allmulti_mode_result { 2787 cmdline_fixed_string_t set; 2788 cmdline_fixed_string_t allmulti; 2789 cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */ 2790 uint8_t port_num; /* valid if "allports" argument == 0 */ 2791 cmdline_fixed_string_t mode; 2792 }; 2793 2794 static void cmd_set_allmulti_mode_parsed(void *parsed_result, 2795 __attribute__((unused)) struct cmdline *cl, 2796 void *allports) 2797 { 2798 struct cmd_set_allmulti_mode_result *res = parsed_result; 2799 int enable; 2800 portid_t i; 2801 2802 if (!strcmp(res->mode, "on")) 2803 enable = 1; 2804 else 2805 enable = 0; 2806 2807 /* all ports */ 2808 if (allports) { 2809 for (i = 0; i < nb_ports; i++) { 2810 if (enable) 2811 rte_eth_allmulticast_enable(i); 2812 else 2813 rte_eth_allmulticast_disable(i); 2814 } 2815 } 2816 else { 2817 if (enable) 2818 rte_eth_allmulticast_enable(res->port_num); 2819 else 2820 rte_eth_allmulticast_disable(res->port_num); 2821 } 2822 } 2823 2824 cmdline_parse_token_string_t cmd_setallmulti_set = 2825 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set"); 2826 cmdline_parse_token_string_t cmd_setallmulti_allmulti = 2827 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti, 2828 "allmulti"); 2829 cmdline_parse_token_string_t cmd_setallmulti_portall = 2830 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all, 2831 "all"); 2832 cmdline_parse_token_num_t cmd_setallmulti_portnum = 2833 TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num, 2834 UINT8); 2835 cmdline_parse_token_string_t cmd_setallmulti_mode = 2836 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode, 2837 "on#off"); 2838 2839 cmdline_parse_inst_t cmd_set_allmulti_mode_all = { 2840 .f = cmd_set_allmulti_mode_parsed, 2841 .data = (void *)1, 2842 .help_str = "set allmulti all on|off: set allmulti mode for all ports", 2843 .tokens = { 2844 (void *)&cmd_setallmulti_set, 2845 (void *)&cmd_setallmulti_allmulti, 2846 (void *)&cmd_setallmulti_portall, 2847 (void *)&cmd_setallmulti_mode, 2848 NULL, 2849 }, 2850 }; 2851 2852 cmdline_parse_inst_t cmd_set_allmulti_mode_one = { 2853 .f = cmd_set_allmulti_mode_parsed, 2854 .data = (void *)0, 2855 .help_str = "set allmulti X on|off: set allmulti mode on port X", 2856 .tokens = { 2857 (void *)&cmd_setallmulti_set, 2858 (void *)&cmd_setallmulti_allmulti, 2859 (void *)&cmd_setallmulti_portnum, 2860 (void *)&cmd_setallmulti_mode, 2861 NULL, 2862 }, 2863 }; 2864 2865 /* *** ADD/REMOVE A PKT FILTER *** */ 2866 struct cmd_pkt_filter_result { 2867 cmdline_fixed_string_t pkt_filter; 2868 uint8_t port_id; 2869 cmdline_fixed_string_t protocol; 2870 cmdline_fixed_string_t src; 2871 cmdline_ipaddr_t ip_src; 2872 uint16_t port_src; 2873 cmdline_fixed_string_t dst; 2874 cmdline_ipaddr_t ip_dst; 2875 uint16_t port_dst; 2876 cmdline_fixed_string_t flexbytes; 2877 uint16_t flexbytes_value; 2878 cmdline_fixed_string_t vlan; 2879 uint16_t vlan_id; 2880 cmdline_fixed_string_t queue; 2881 int8_t queue_id; 2882 cmdline_fixed_string_t soft; 2883 uint8_t soft_id; 2884 }; 2885 2886 static void 2887 cmd_pkt_filter_parsed(void *parsed_result, 2888 __attribute__((unused)) struct cmdline *cl, 2889 __attribute__((unused)) void *data) 2890 { 2891 struct rte_fdir_filter fdir_filter; 2892 struct cmd_pkt_filter_result *res = parsed_result; 2893 2894 memset(&fdir_filter, 0, sizeof(struct rte_fdir_filter)); 2895 2896 if (res->ip_src.family == AF_INET) 2897 fdir_filter.ip_src.ipv4_addr = res->ip_src.addr.ipv4.s_addr; 2898 else 2899 memcpy(&(fdir_filter.ip_src.ipv6_addr), 2900 &(res->ip_src.addr.ipv6), 2901 sizeof(struct in6_addr)); 2902 2903 if (res->ip_dst.family == AF_INET) 2904 fdir_filter.ip_dst.ipv4_addr = res->ip_dst.addr.ipv4.s_addr; 2905 else 2906 memcpy(&(fdir_filter.ip_dst.ipv6_addr), 2907 &(res->ip_dst.addr.ipv6), 2908 sizeof(struct in6_addr)); 2909 2910 fdir_filter.port_dst = rte_cpu_to_be_16(res->port_dst); 2911 fdir_filter.port_src = rte_cpu_to_be_16(res->port_src); 2912 2913 if (!strcmp(res->protocol, "udp")) 2914 fdir_filter.l4type = RTE_FDIR_L4TYPE_UDP; 2915 else if (!strcmp(res->protocol, "tcp")) 2916 fdir_filter.l4type = RTE_FDIR_L4TYPE_TCP; 2917 else if (!strcmp(res->protocol, "sctp")) 2918 fdir_filter.l4type = RTE_FDIR_L4TYPE_SCTP; 2919 else /* default only IP */ 2920 fdir_filter.l4type = RTE_FDIR_L4TYPE_NONE; 2921 2922 if (res->ip_dst.family == AF_INET6) 2923 fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV6; 2924 else 2925 fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV4; 2926 2927 fdir_filter.vlan_id = rte_cpu_to_be_16(res->vlan_id); 2928 fdir_filter.flex_bytes = rte_cpu_to_be_16(res->flexbytes_value); 2929 2930 if (!strcmp(res->pkt_filter, "add_signature_filter")) 2931 fdir_add_signature_filter(res->port_id, res->queue_id, 2932 &fdir_filter); 2933 else if (!strcmp(res->pkt_filter, "upd_signature_filter")) 2934 fdir_update_signature_filter(res->port_id, res->queue_id, 2935 &fdir_filter); 2936 else if (!strcmp(res->pkt_filter, "rm_signature_filter")) 2937 fdir_remove_signature_filter(res->port_id, &fdir_filter); 2938 else if (!strcmp(res->pkt_filter, "add_perfect_filter")) 2939 fdir_add_perfect_filter(res->port_id, res->soft_id, 2940 res->queue_id, 2941 (uint8_t) (res->queue_id < 0), 2942 &fdir_filter); 2943 else if (!strcmp(res->pkt_filter, "upd_perfect_filter")) 2944 fdir_update_perfect_filter(res->port_id, res->soft_id, 2945 res->queue_id, 2946 (uint8_t) (res->queue_id < 0), 2947 &fdir_filter); 2948 else if (!strcmp(res->pkt_filter, "rm_perfect_filter")) 2949 fdir_remove_perfect_filter(res->port_id, res->soft_id, 2950 &fdir_filter); 2951 2952 } 2953 2954 2955 cmdline_parse_token_num_t cmd_pkt_filter_port_id = 2956 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result, 2957 port_id, UINT8); 2958 cmdline_parse_token_string_t cmd_pkt_filter_protocol = 2959 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result, 2960 protocol, "ip#tcp#udp#sctp"); 2961 cmdline_parse_token_string_t cmd_pkt_filter_src = 2962 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result, 2963 src, "src"); 2964 cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_src = 2965 TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result, 2966 ip_src); 2967 cmdline_parse_token_num_t cmd_pkt_filter_port_src = 2968 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result, 2969 port_src, UINT16); 2970 cmdline_parse_token_string_t cmd_pkt_filter_dst = 2971 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result, 2972 dst, "dst"); 2973 cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_dst = 2974 TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result, 2975 ip_dst); 2976 cmdline_parse_token_num_t cmd_pkt_filter_port_dst = 2977 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result, 2978 port_dst, UINT16); 2979 cmdline_parse_token_string_t cmd_pkt_filter_flexbytes = 2980 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result, 2981 flexbytes, "flexbytes"); 2982 cmdline_parse_token_num_t cmd_pkt_filter_flexbytes_value = 2983 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result, 2984 flexbytes_value, UINT16); 2985 cmdline_parse_token_string_t cmd_pkt_filter_vlan = 2986 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result, 2987 vlan, "vlan"); 2988 cmdline_parse_token_num_t cmd_pkt_filter_vlan_id = 2989 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result, 2990 vlan_id, UINT16); 2991 cmdline_parse_token_string_t cmd_pkt_filter_queue = 2992 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result, 2993 queue, "queue"); 2994 cmdline_parse_token_num_t cmd_pkt_filter_queue_id = 2995 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result, 2996 queue_id, INT8); 2997 cmdline_parse_token_string_t cmd_pkt_filter_soft = 2998 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result, 2999 soft, "soft"); 3000 cmdline_parse_token_num_t cmd_pkt_filter_soft_id = 3001 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result, 3002 soft_id, UINT16); 3003 3004 3005 cmdline_parse_token_string_t cmd_pkt_filter_add_signature_filter = 3006 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result, 3007 pkt_filter, "add_signature_filter"); 3008 cmdline_parse_inst_t cmd_add_signature_filter = { 3009 .f = cmd_pkt_filter_parsed, 3010 .data = NULL, 3011 .help_str = "add a signature filter", 3012 .tokens = { 3013 (void *)&cmd_pkt_filter_add_signature_filter, 3014 (void *)&cmd_pkt_filter_port_id, 3015 (void *)&cmd_pkt_filter_protocol, 3016 (void *)&cmd_pkt_filter_src, 3017 (void *)&cmd_pkt_filter_ip_src, 3018 (void *)&cmd_pkt_filter_port_src, 3019 (void *)&cmd_pkt_filter_dst, 3020 (void *)&cmd_pkt_filter_ip_dst, 3021 (void *)&cmd_pkt_filter_port_dst, 3022 (void *)&cmd_pkt_filter_flexbytes, 3023 (void *)&cmd_pkt_filter_flexbytes_value, 3024 (void *)&cmd_pkt_filter_vlan, 3025 (void *)&cmd_pkt_filter_vlan_id, 3026 (void *)&cmd_pkt_filter_queue, 3027 (void *)&cmd_pkt_filter_queue_id, 3028 NULL, 3029 }, 3030 }; 3031 3032 3033 cmdline_parse_token_string_t cmd_pkt_filter_upd_signature_filter = 3034 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result, 3035 pkt_filter, "upd_signature_filter"); 3036 cmdline_parse_inst_t cmd_upd_signature_filter = { 3037 .f = cmd_pkt_filter_parsed, 3038 .data = NULL, 3039 .help_str = "update a signature filter", 3040 .tokens = { 3041 (void *)&cmd_pkt_filter_upd_signature_filter, 3042 (void *)&cmd_pkt_filter_port_id, 3043 (void *)&cmd_pkt_filter_protocol, 3044 (void *)&cmd_pkt_filter_src, 3045 (void *)&cmd_pkt_filter_ip_src, 3046 (void *)&cmd_pkt_filter_port_src, 3047 (void *)&cmd_pkt_filter_dst, 3048 (void *)&cmd_pkt_filter_ip_dst, 3049 (void *)&cmd_pkt_filter_port_dst, 3050 (void *)&cmd_pkt_filter_flexbytes, 3051 (void *)&cmd_pkt_filter_flexbytes_value, 3052 (void *)&cmd_pkt_filter_vlan, 3053 (void *)&cmd_pkt_filter_vlan_id, 3054 (void *)&cmd_pkt_filter_queue, 3055 (void *)&cmd_pkt_filter_queue_id, 3056 NULL, 3057 }, 3058 }; 3059 3060 3061 cmdline_parse_token_string_t cmd_pkt_filter_rm_signature_filter = 3062 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result, 3063 pkt_filter, "rm_signature_filter"); 3064 cmdline_parse_inst_t cmd_rm_signature_filter = { 3065 .f = cmd_pkt_filter_parsed, 3066 .data = NULL, 3067 .help_str = "remove a signature filter", 3068 .tokens = { 3069 (void *)&cmd_pkt_filter_rm_signature_filter, 3070 (void *)&cmd_pkt_filter_port_id, 3071 (void *)&cmd_pkt_filter_protocol, 3072 (void *)&cmd_pkt_filter_src, 3073 (void *)&cmd_pkt_filter_ip_src, 3074 (void *)&cmd_pkt_filter_port_src, 3075 (void *)&cmd_pkt_filter_dst, 3076 (void *)&cmd_pkt_filter_ip_dst, 3077 (void *)&cmd_pkt_filter_port_dst, 3078 (void *)&cmd_pkt_filter_flexbytes, 3079 (void *)&cmd_pkt_filter_flexbytes_value, 3080 (void *)&cmd_pkt_filter_vlan, 3081 (void *)&cmd_pkt_filter_vlan_id, 3082 NULL 3083 }, 3084 }; 3085 3086 3087 cmdline_parse_token_string_t cmd_pkt_filter_add_perfect_filter = 3088 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result, 3089 pkt_filter, "add_perfect_filter"); 3090 cmdline_parse_inst_t cmd_add_perfect_filter = { 3091 .f = cmd_pkt_filter_parsed, 3092 .data = NULL, 3093 .help_str = "add a perfect filter", 3094 .tokens = { 3095 (void *)&cmd_pkt_filter_add_perfect_filter, 3096 (void *)&cmd_pkt_filter_port_id, 3097 (void *)&cmd_pkt_filter_protocol, 3098 (void *)&cmd_pkt_filter_src, 3099 (void *)&cmd_pkt_filter_ip_src, 3100 (void *)&cmd_pkt_filter_port_src, 3101 (void *)&cmd_pkt_filter_dst, 3102 (void *)&cmd_pkt_filter_ip_dst, 3103 (void *)&cmd_pkt_filter_port_dst, 3104 (void *)&cmd_pkt_filter_flexbytes, 3105 (void *)&cmd_pkt_filter_flexbytes_value, 3106 (void *)&cmd_pkt_filter_vlan, 3107 (void *)&cmd_pkt_filter_vlan_id, 3108 (void *)&cmd_pkt_filter_queue, 3109 (void *)&cmd_pkt_filter_queue_id, 3110 (void *)&cmd_pkt_filter_soft, 3111 (void *)&cmd_pkt_filter_soft_id, 3112 NULL, 3113 }, 3114 }; 3115 3116 3117 cmdline_parse_token_string_t cmd_pkt_filter_upd_perfect_filter = 3118 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result, 3119 pkt_filter, "upd_perfect_filter"); 3120 cmdline_parse_inst_t cmd_upd_perfect_filter = { 3121 .f = cmd_pkt_filter_parsed, 3122 .data = NULL, 3123 .help_str = "update a perfect filter", 3124 .tokens = { 3125 (void *)&cmd_pkt_filter_upd_perfect_filter, 3126 (void *)&cmd_pkt_filter_port_id, 3127 (void *)&cmd_pkt_filter_protocol, 3128 (void *)&cmd_pkt_filter_src, 3129 (void *)&cmd_pkt_filter_ip_src, 3130 (void *)&cmd_pkt_filter_port_src, 3131 (void *)&cmd_pkt_filter_dst, 3132 (void *)&cmd_pkt_filter_ip_dst, 3133 (void *)&cmd_pkt_filter_port_dst, 3134 (void *)&cmd_pkt_filter_flexbytes, 3135 (void *)&cmd_pkt_filter_flexbytes_value, 3136 (void *)&cmd_pkt_filter_vlan, 3137 (void *)&cmd_pkt_filter_vlan_id, 3138 (void *)&cmd_pkt_filter_queue, 3139 (void *)&cmd_pkt_filter_queue_id, 3140 (void *)&cmd_pkt_filter_soft, 3141 (void *)&cmd_pkt_filter_soft_id, 3142 NULL, 3143 }, 3144 }; 3145 3146 3147 cmdline_parse_token_string_t cmd_pkt_filter_rm_perfect_filter = 3148 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result, 3149 pkt_filter, "rm_perfect_filter"); 3150 cmdline_parse_inst_t cmd_rm_perfect_filter = { 3151 .f = cmd_pkt_filter_parsed, 3152 .data = NULL, 3153 .help_str = "remove a perfect filter", 3154 .tokens = { 3155 (void *)&cmd_pkt_filter_rm_perfect_filter, 3156 (void *)&cmd_pkt_filter_port_id, 3157 (void *)&cmd_pkt_filter_protocol, 3158 (void *)&cmd_pkt_filter_src, 3159 (void *)&cmd_pkt_filter_ip_src, 3160 (void *)&cmd_pkt_filter_port_src, 3161 (void *)&cmd_pkt_filter_dst, 3162 (void *)&cmd_pkt_filter_ip_dst, 3163 (void *)&cmd_pkt_filter_port_dst, 3164 (void *)&cmd_pkt_filter_flexbytes, 3165 (void *)&cmd_pkt_filter_flexbytes_value, 3166 (void *)&cmd_pkt_filter_vlan, 3167 (void *)&cmd_pkt_filter_vlan_id, 3168 (void *)&cmd_pkt_filter_soft, 3169 (void *)&cmd_pkt_filter_soft_id, 3170 NULL, 3171 }, 3172 }; 3173 3174 /* *** SETUP MASKS FILTER *** */ 3175 struct cmd_pkt_filter_masks_result { 3176 cmdline_fixed_string_t filter_mask; 3177 uint8_t port_id; 3178 cmdline_fixed_string_t src_mask; 3179 uint32_t ip_src_mask; 3180 uint16_t ipv6_src_mask; 3181 uint16_t port_src_mask; 3182 cmdline_fixed_string_t dst_mask; 3183 uint32_t ip_dst_mask; 3184 uint16_t ipv6_dst_mask; 3185 uint16_t port_dst_mask; 3186 cmdline_fixed_string_t flexbytes; 3187 uint8_t flexbytes_value; 3188 cmdline_fixed_string_t vlan_id; 3189 uint8_t vlan_id_value; 3190 cmdline_fixed_string_t vlan_prio; 3191 uint8_t vlan_prio_value; 3192 cmdline_fixed_string_t only_ip_flow; 3193 uint8_t only_ip_flow_value; 3194 cmdline_fixed_string_t comp_ipv6_dst; 3195 uint8_t comp_ipv6_dst_value; 3196 }; 3197 3198 static void 3199 cmd_pkt_filter_masks_parsed(void *parsed_result, 3200 __attribute__((unused)) struct cmdline *cl, 3201 __attribute__((unused)) void *data) 3202 { 3203 struct rte_fdir_masks fdir_masks; 3204 struct cmd_pkt_filter_masks_result *res = parsed_result; 3205 3206 memset(&fdir_masks, 0, sizeof(struct rte_fdir_masks)); 3207 3208 fdir_masks.only_ip_flow = res->only_ip_flow_value; 3209 fdir_masks.vlan_id = res->vlan_id_value; 3210 fdir_masks.vlan_prio = res->vlan_prio_value; 3211 fdir_masks.dst_ipv4_mask = res->ip_dst_mask; 3212 fdir_masks.src_ipv4_mask = res->ip_src_mask; 3213 fdir_masks.src_port_mask = res->port_src_mask; 3214 fdir_masks.dst_port_mask = res->port_dst_mask; 3215 fdir_masks.flexbytes = res->flexbytes_value; 3216 3217 fdir_set_masks(res->port_id, &fdir_masks); 3218 } 3219 3220 cmdline_parse_token_string_t cmd_pkt_filter_masks_filter_mask = 3221 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result, 3222 filter_mask, "set_masks_filter"); 3223 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_id = 3224 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result, 3225 port_id, UINT8); 3226 cmdline_parse_token_string_t cmd_pkt_filter_masks_only_ip_flow = 3227 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result, 3228 only_ip_flow, "only_ip_flow"); 3229 cmdline_parse_token_num_t cmd_pkt_filter_masks_only_ip_flow_value = 3230 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result, 3231 only_ip_flow_value, UINT8); 3232 cmdline_parse_token_string_t cmd_pkt_filter_masks_src_mask = 3233 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result, 3234 src_mask, "src_mask"); 3235 cmdline_parse_token_num_t cmd_pkt_filter_masks_ip_src_mask = 3236 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result, 3237 ip_src_mask, UINT32); 3238 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_src_mask = 3239 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result, 3240 port_src_mask, UINT16); 3241 cmdline_parse_token_string_t cmd_pkt_filter_masks_dst_mask = 3242 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result, 3243 dst_mask, "dst_mask"); 3244 cmdline_parse_token_num_t cmd_pkt_filter_masks_ip_dst_mask = 3245 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result, 3246 ip_dst_mask, UINT32); 3247 cmdline_parse_token_num_t cmd_pkt_filter_masks_port_dst_mask = 3248 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result, 3249 port_dst_mask, UINT16); 3250 cmdline_parse_token_string_t cmd_pkt_filter_masks_flexbytes = 3251 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result, 3252 flexbytes, "flexbytes"); 3253 cmdline_parse_token_num_t cmd_pkt_filter_masks_flexbytes_value = 3254 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result, 3255 flexbytes_value, UINT8); 3256 cmdline_parse_token_string_t cmd_pkt_filter_masks_vlan_id = 3257 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result, 3258 vlan_id, "vlan_id"); 3259 cmdline_parse_token_num_t cmd_pkt_filter_masks_vlan_id_value = 3260 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result, 3261 vlan_id_value, UINT8); 3262 cmdline_parse_token_string_t cmd_pkt_filter_masks_vlan_prio = 3263 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result, 3264 vlan_prio, "vlan_prio"); 3265 cmdline_parse_token_num_t cmd_pkt_filter_masks_vlan_prio_value = 3266 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result, 3267 vlan_prio_value, UINT8); 3268 3269 cmdline_parse_inst_t cmd_set_masks_filter = { 3270 .f = cmd_pkt_filter_masks_parsed, 3271 .data = NULL, 3272 .help_str = "setup masks filter", 3273 .tokens = { 3274 (void *)&cmd_pkt_filter_masks_filter_mask, 3275 (void *)&cmd_pkt_filter_masks_port_id, 3276 (void *)&cmd_pkt_filter_masks_only_ip_flow, 3277 (void *)&cmd_pkt_filter_masks_only_ip_flow_value, 3278 (void *)&cmd_pkt_filter_masks_src_mask, 3279 (void *)&cmd_pkt_filter_masks_ip_src_mask, 3280 (void *)&cmd_pkt_filter_masks_port_src_mask, 3281 (void *)&cmd_pkt_filter_masks_dst_mask, 3282 (void *)&cmd_pkt_filter_masks_ip_dst_mask, 3283 (void *)&cmd_pkt_filter_masks_port_dst_mask, 3284 (void *)&cmd_pkt_filter_masks_flexbytes, 3285 (void *)&cmd_pkt_filter_masks_flexbytes_value, 3286 (void *)&cmd_pkt_filter_masks_vlan_id, 3287 (void *)&cmd_pkt_filter_masks_vlan_id_value, 3288 (void *)&cmd_pkt_filter_masks_vlan_prio, 3289 (void *)&cmd_pkt_filter_masks_vlan_prio_value, 3290 NULL, 3291 }, 3292 }; 3293 3294 static void 3295 cmd_pkt_filter_masks_ipv6_parsed(void *parsed_result, 3296 __attribute__((unused)) struct cmdline *cl, 3297 __attribute__((unused)) void *data) 3298 { 3299 struct rte_fdir_masks fdir_masks; 3300 struct cmd_pkt_filter_masks_result *res = parsed_result; 3301 3302 memset(&fdir_masks, 0, sizeof(struct rte_fdir_masks)); 3303 3304 fdir_masks.set_ipv6_mask = 1; 3305 fdir_masks.only_ip_flow = res->only_ip_flow_value; 3306 fdir_masks.vlan_id = res->vlan_id_value; 3307 fdir_masks.vlan_prio = res->vlan_prio_value; 3308 fdir_masks.dst_ipv6_mask = res->ipv6_dst_mask; 3309 fdir_masks.src_ipv6_mask = res->ipv6_src_mask; 3310 fdir_masks.src_port_mask = res->port_src_mask; 3311 fdir_masks.dst_port_mask = res->port_dst_mask; 3312 fdir_masks.flexbytes = res->flexbytes_value; 3313 fdir_masks.comp_ipv6_dst = res->comp_ipv6_dst_value; 3314 3315 fdir_set_masks(res->port_id, &fdir_masks); 3316 } 3317 3318 cmdline_parse_token_string_t cmd_pkt_filter_masks_filter_mask_ipv6 = 3319 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result, 3320 filter_mask, "set_ipv6_masks_filter"); 3321 cmdline_parse_token_num_t cmd_pkt_filter_masks_src_mask_ipv6_value = 3322 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result, 3323 ipv6_src_mask, UINT16); 3324 cmdline_parse_token_num_t cmd_pkt_filter_masks_dst_mask_ipv6_value = 3325 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result, 3326 ipv6_dst_mask, UINT16); 3327 3328 cmdline_parse_token_string_t cmd_pkt_filter_masks_comp_ipv6_dst = 3329 TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_masks_result, 3330 comp_ipv6_dst, "compare_dst"); 3331 cmdline_parse_token_num_t cmd_pkt_filter_masks_comp_ipv6_dst_value = 3332 TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_masks_result, 3333 comp_ipv6_dst_value, UINT8); 3334 3335 cmdline_parse_inst_t cmd_set_ipv6_masks_filter = { 3336 .f = cmd_pkt_filter_masks_ipv6_parsed, 3337 .data = NULL, 3338 .help_str = "setup ipv6 masks filter", 3339 .tokens = { 3340 (void *)&cmd_pkt_filter_masks_filter_mask_ipv6, 3341 (void *)&cmd_pkt_filter_masks_port_id, 3342 (void *)&cmd_pkt_filter_masks_only_ip_flow, 3343 (void *)&cmd_pkt_filter_masks_only_ip_flow_value, 3344 (void *)&cmd_pkt_filter_masks_src_mask, 3345 (void *)&cmd_pkt_filter_masks_src_mask_ipv6_value, 3346 (void *)&cmd_pkt_filter_masks_port_src_mask, 3347 (void *)&cmd_pkt_filter_masks_dst_mask, 3348 (void *)&cmd_pkt_filter_masks_dst_mask_ipv6_value, 3349 (void *)&cmd_pkt_filter_masks_port_dst_mask, 3350 (void *)&cmd_pkt_filter_masks_flexbytes, 3351 (void *)&cmd_pkt_filter_masks_flexbytes_value, 3352 (void *)&cmd_pkt_filter_masks_vlan_id, 3353 (void *)&cmd_pkt_filter_masks_vlan_id_value, 3354 (void *)&cmd_pkt_filter_masks_vlan_prio, 3355 (void *)&cmd_pkt_filter_masks_vlan_prio_value, 3356 (void *)&cmd_pkt_filter_masks_comp_ipv6_dst, 3357 (void *)&cmd_pkt_filter_masks_comp_ipv6_dst_value, 3358 NULL, 3359 }, 3360 }; 3361 3362 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */ 3363 struct cmd_link_flow_ctrl_set_result { 3364 cmdline_fixed_string_t set; 3365 cmdline_fixed_string_t flow_ctrl; 3366 cmdline_fixed_string_t rx; 3367 cmdline_fixed_string_t rx_lfc_mode; 3368 cmdline_fixed_string_t tx; 3369 cmdline_fixed_string_t tx_lfc_mode; 3370 cmdline_fixed_string_t mac_ctrl_frame_fwd; 3371 cmdline_fixed_string_t mac_ctrl_frame_fwd_mode; 3372 uint32_t high_water; 3373 uint32_t low_water; 3374 uint16_t pause_time; 3375 uint16_t send_xon; 3376 uint8_t port_id; 3377 }; 3378 3379 static void 3380 cmd_link_flow_ctrl_set_parsed(void *parsed_result, 3381 __attribute__((unused)) struct cmdline *cl, 3382 __attribute__((unused)) void *data) 3383 { 3384 struct cmd_link_flow_ctrl_set_result *res = parsed_result; 3385 struct rte_eth_fc_conf fc_conf; 3386 int rx_fc_enable, tx_fc_enable, mac_ctrl_frame_fwd; 3387 int ret; 3388 3389 /* 3390 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate 3391 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side. 3392 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate 3393 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side. 3394 */ 3395 static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = { 3396 {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL} 3397 }; 3398 3399 rx_fc_enable = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0; 3400 tx_fc_enable = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0; 3401 mac_ctrl_frame_fwd = (!strcmp(res->mac_ctrl_frame_fwd_mode, "on")) ? 1 : 0; 3402 3403 fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_enable][tx_fc_enable]; 3404 fc_conf.high_water = res->high_water; 3405 fc_conf.low_water = res->low_water; 3406 fc_conf.pause_time = res->pause_time; 3407 fc_conf.send_xon = res->send_xon; 3408 fc_conf.mac_ctrl_frame_fwd = (uint8_t)mac_ctrl_frame_fwd; 3409 3410 ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf); 3411 if (ret != 0) 3412 printf("bad flow contrl parameter, return code = %d \n", ret); 3413 } 3414 3415 cmdline_parse_token_string_t cmd_lfc_set_set = 3416 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 3417 set, "set"); 3418 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl = 3419 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 3420 flow_ctrl, "flow_ctrl"); 3421 cmdline_parse_token_string_t cmd_lfc_set_rx = 3422 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 3423 rx, "rx"); 3424 cmdline_parse_token_string_t cmd_lfc_set_rx_mode = 3425 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 3426 rx_lfc_mode, "on#off"); 3427 cmdline_parse_token_string_t cmd_lfc_set_tx = 3428 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 3429 tx, "tx"); 3430 cmdline_parse_token_string_t cmd_lfc_set_tx_mode = 3431 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 3432 tx_lfc_mode, "on#off"); 3433 cmdline_parse_token_num_t cmd_lfc_set_high_water = 3434 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 3435 high_water, UINT32); 3436 cmdline_parse_token_num_t cmd_lfc_set_low_water = 3437 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 3438 low_water, UINT32); 3439 cmdline_parse_token_num_t cmd_lfc_set_pause_time = 3440 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 3441 pause_time, UINT16); 3442 cmdline_parse_token_num_t cmd_lfc_set_send_xon = 3443 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 3444 send_xon, UINT16); 3445 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode = 3446 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 3447 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd"); 3448 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd = 3449 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 3450 mac_ctrl_frame_fwd_mode, "on#off"); 3451 cmdline_parse_token_num_t cmd_lfc_set_portid = 3452 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 3453 port_id, UINT8); 3454 3455 cmdline_parse_inst_t cmd_link_flow_control_set = { 3456 .f = cmd_link_flow_ctrl_set_parsed, 3457 .data = NULL, 3458 .help_str = "Configure the Ethernet flow control: set flow_ctrl rx on|off \ 3459 tx on|off high_water low_water pause_time send_xon mac_ctrl_frame_fwd on|off \ 3460 port_id", 3461 .tokens = { 3462 (void *)&cmd_lfc_set_set, 3463 (void *)&cmd_lfc_set_flow_ctrl, 3464 (void *)&cmd_lfc_set_rx, 3465 (void *)&cmd_lfc_set_rx_mode, 3466 (void *)&cmd_lfc_set_tx, 3467 (void *)&cmd_lfc_set_tx_mode, 3468 (void *)&cmd_lfc_set_high_water, 3469 (void *)&cmd_lfc_set_low_water, 3470 (void *)&cmd_lfc_set_pause_time, 3471 (void *)&cmd_lfc_set_send_xon, 3472 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode, 3473 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd, 3474 (void *)&cmd_lfc_set_portid, 3475 NULL, 3476 }, 3477 }; 3478 3479 /* *** SETUP ETHERNET PIRORITY FLOW CONTROL *** */ 3480 struct cmd_priority_flow_ctrl_set_result { 3481 cmdline_fixed_string_t set; 3482 cmdline_fixed_string_t pfc_ctrl; 3483 cmdline_fixed_string_t rx; 3484 cmdline_fixed_string_t rx_pfc_mode; 3485 cmdline_fixed_string_t tx; 3486 cmdline_fixed_string_t tx_pfc_mode; 3487 uint32_t high_water; 3488 uint32_t low_water; 3489 uint16_t pause_time; 3490 uint8_t priority; 3491 uint8_t port_id; 3492 }; 3493 3494 static void 3495 cmd_priority_flow_ctrl_set_parsed(void *parsed_result, 3496 __attribute__((unused)) struct cmdline *cl, 3497 __attribute__((unused)) void *data) 3498 { 3499 struct cmd_priority_flow_ctrl_set_result *res = parsed_result; 3500 struct rte_eth_pfc_conf pfc_conf; 3501 int rx_fc_enable, tx_fc_enable; 3502 int ret; 3503 3504 /* 3505 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate 3506 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side. 3507 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate 3508 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side. 3509 */ 3510 static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = { 3511 {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL} 3512 }; 3513 3514 rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0; 3515 tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0; 3516 pfc_conf.fc.mode = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable]; 3517 pfc_conf.fc.high_water = res->high_water; 3518 pfc_conf.fc.low_water = res->low_water; 3519 pfc_conf.fc.pause_time = res->pause_time; 3520 pfc_conf.priority = res->priority; 3521 3522 ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf); 3523 if (ret != 0) 3524 printf("bad priority flow contrl parameter, return code = %d \n", ret); 3525 } 3526 3527 cmdline_parse_token_string_t cmd_pfc_set_set = 3528 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 3529 set, "set"); 3530 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl = 3531 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 3532 pfc_ctrl, "pfc_ctrl"); 3533 cmdline_parse_token_string_t cmd_pfc_set_rx = 3534 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 3535 rx, "rx"); 3536 cmdline_parse_token_string_t cmd_pfc_set_rx_mode = 3537 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 3538 rx_pfc_mode, "on#off"); 3539 cmdline_parse_token_string_t cmd_pfc_set_tx = 3540 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 3541 tx, "tx"); 3542 cmdline_parse_token_string_t cmd_pfc_set_tx_mode = 3543 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 3544 tx_pfc_mode, "on#off"); 3545 cmdline_parse_token_num_t cmd_pfc_set_high_water = 3546 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 3547 high_water, UINT32); 3548 cmdline_parse_token_num_t cmd_pfc_set_low_water = 3549 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 3550 low_water, UINT32); 3551 cmdline_parse_token_num_t cmd_pfc_set_pause_time = 3552 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 3553 pause_time, UINT16); 3554 cmdline_parse_token_num_t cmd_pfc_set_priority = 3555 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 3556 priority, UINT8); 3557 cmdline_parse_token_num_t cmd_pfc_set_portid = 3558 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 3559 port_id, UINT8); 3560 3561 cmdline_parse_inst_t cmd_priority_flow_control_set = { 3562 .f = cmd_priority_flow_ctrl_set_parsed, 3563 .data = NULL, 3564 .help_str = "Configure the Ethernet priority flow control: set pfc_ctrl rx on|off\n\ 3565 tx on|off high_water low_water pause_time priority port_id", 3566 .tokens = { 3567 (void *)&cmd_pfc_set_set, 3568 (void *)&cmd_pfc_set_flow_ctrl, 3569 (void *)&cmd_pfc_set_rx, 3570 (void *)&cmd_pfc_set_rx_mode, 3571 (void *)&cmd_pfc_set_tx, 3572 (void *)&cmd_pfc_set_tx_mode, 3573 (void *)&cmd_pfc_set_high_water, 3574 (void *)&cmd_pfc_set_low_water, 3575 (void *)&cmd_pfc_set_pause_time, 3576 (void *)&cmd_pfc_set_priority, 3577 (void *)&cmd_pfc_set_portid, 3578 NULL, 3579 }, 3580 }; 3581 3582 /* *** RESET CONFIGURATION *** */ 3583 struct cmd_reset_result { 3584 cmdline_fixed_string_t reset; 3585 cmdline_fixed_string_t def; 3586 }; 3587 3588 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result, 3589 struct cmdline *cl, 3590 __attribute__((unused)) void *data) 3591 { 3592 cmdline_printf(cl, "Reset to default forwarding configuration...\n"); 3593 set_def_fwd_config(); 3594 } 3595 3596 cmdline_parse_token_string_t cmd_reset_set = 3597 TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set"); 3598 cmdline_parse_token_string_t cmd_reset_def = 3599 TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def, 3600 "default"); 3601 3602 cmdline_parse_inst_t cmd_reset = { 3603 .f = cmd_reset_parsed, 3604 .data = NULL, 3605 .help_str = "set default: reset default forwarding configuration", 3606 .tokens = { 3607 (void *)&cmd_reset_set, 3608 (void *)&cmd_reset_def, 3609 NULL, 3610 }, 3611 }; 3612 3613 /* *** START FORWARDING *** */ 3614 struct cmd_start_result { 3615 cmdline_fixed_string_t start; 3616 }; 3617 3618 cmdline_parse_token_string_t cmd_start_start = 3619 TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start"); 3620 3621 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result, 3622 __attribute__((unused)) struct cmdline *cl, 3623 __attribute__((unused)) void *data) 3624 { 3625 start_packet_forwarding(0); 3626 } 3627 3628 cmdline_parse_inst_t cmd_start = { 3629 .f = cmd_start_parsed, 3630 .data = NULL, 3631 .help_str = "start packet forwarding", 3632 .tokens = { 3633 (void *)&cmd_start_start, 3634 NULL, 3635 }, 3636 }; 3637 3638 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */ 3639 struct cmd_start_tx_first_result { 3640 cmdline_fixed_string_t start; 3641 cmdline_fixed_string_t tx_first; 3642 }; 3643 3644 static void 3645 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result, 3646 __attribute__((unused)) struct cmdline *cl, 3647 __attribute__((unused)) void *data) 3648 { 3649 start_packet_forwarding(1); 3650 } 3651 3652 cmdline_parse_token_string_t cmd_start_tx_first_start = 3653 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start, 3654 "start"); 3655 cmdline_parse_token_string_t cmd_start_tx_first_tx_first = 3656 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, 3657 tx_first, "tx_first"); 3658 3659 cmdline_parse_inst_t cmd_start_tx_first = { 3660 .f = cmd_start_tx_first_parsed, 3661 .data = NULL, 3662 .help_str = "start packet forwarding, after sending 1 burst of packets", 3663 .tokens = { 3664 (void *)&cmd_start_tx_first_start, 3665 (void *)&cmd_start_tx_first_tx_first, 3666 NULL, 3667 }, 3668 }; 3669 3670 /* *** SHOW CFG *** */ 3671 struct cmd_showcfg_result { 3672 cmdline_fixed_string_t show; 3673 cmdline_fixed_string_t cfg; 3674 cmdline_fixed_string_t what; 3675 }; 3676 3677 static void cmd_showcfg_parsed(void *parsed_result, 3678 __attribute__((unused)) struct cmdline *cl, 3679 __attribute__((unused)) void *data) 3680 { 3681 struct cmd_showcfg_result *res = parsed_result; 3682 if (!strcmp(res->what, "rxtx")) 3683 rxtx_config_display(); 3684 else if (!strcmp(res->what, "cores")) 3685 fwd_lcores_config_display(); 3686 else if (!strcmp(res->what, "fwd")) 3687 fwd_config_display(); 3688 } 3689 3690 cmdline_parse_token_string_t cmd_showcfg_show = 3691 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show"); 3692 cmdline_parse_token_string_t cmd_showcfg_port = 3693 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config"); 3694 cmdline_parse_token_string_t cmd_showcfg_what = 3695 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what, 3696 "rxtx#cores#fwd"); 3697 3698 cmdline_parse_inst_t cmd_showcfg = { 3699 .f = cmd_showcfg_parsed, 3700 .data = NULL, 3701 .help_str = "show config rxtx|cores|fwd", 3702 .tokens = { 3703 (void *)&cmd_showcfg_show, 3704 (void *)&cmd_showcfg_port, 3705 (void *)&cmd_showcfg_what, 3706 NULL, 3707 }, 3708 }; 3709 3710 /* *** SHOW ALL PORT INFO *** */ 3711 struct cmd_showportall_result { 3712 cmdline_fixed_string_t show; 3713 cmdline_fixed_string_t port; 3714 cmdline_fixed_string_t what; 3715 cmdline_fixed_string_t all; 3716 }; 3717 3718 static void cmd_showportall_parsed(void *parsed_result, 3719 __attribute__((unused)) struct cmdline *cl, 3720 __attribute__((unused)) void *data) 3721 { 3722 portid_t i; 3723 3724 struct cmd_showportall_result *res = parsed_result; 3725 if (!strcmp(res->show, "clear")) { 3726 if (!strcmp(res->what, "stats")) 3727 for (i = 0; i < nb_ports; i++) 3728 nic_stats_clear(i); 3729 } else if (!strcmp(res->what, "info")) 3730 for (i = 0; i < nb_ports; i++) 3731 port_infos_display(i); 3732 else if (!strcmp(res->what, "stats")) 3733 for (i = 0; i < nb_ports; i++) 3734 nic_stats_display(i); 3735 else if (!strcmp(res->what, "fdir")) 3736 for (i = 0; i < nb_ports; i++) 3737 fdir_get_infos(i); 3738 else if (!strcmp(res->what, "stat_qmap")) 3739 for (i = 0; i < nb_ports; i++) 3740 nic_stats_mapping_display(i); 3741 } 3742 3743 cmdline_parse_token_string_t cmd_showportall_show = 3744 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show, 3745 "show#clear"); 3746 cmdline_parse_token_string_t cmd_showportall_port = 3747 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port"); 3748 cmdline_parse_token_string_t cmd_showportall_what = 3749 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what, 3750 "info#stats#fdir#stat_qmap"); 3751 cmdline_parse_token_string_t cmd_showportall_all = 3752 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all"); 3753 cmdline_parse_inst_t cmd_showportall = { 3754 .f = cmd_showportall_parsed, 3755 .data = NULL, 3756 .help_str = "show|clear port info|stats|fdir|stat_qmap all", 3757 .tokens = { 3758 (void *)&cmd_showportall_show, 3759 (void *)&cmd_showportall_port, 3760 (void *)&cmd_showportall_what, 3761 (void *)&cmd_showportall_all, 3762 NULL, 3763 }, 3764 }; 3765 3766 /* *** SHOW PORT INFO *** */ 3767 struct cmd_showport_result { 3768 cmdline_fixed_string_t show; 3769 cmdline_fixed_string_t port; 3770 cmdline_fixed_string_t what; 3771 uint8_t portnum; 3772 }; 3773 3774 static void cmd_showport_parsed(void *parsed_result, 3775 __attribute__((unused)) struct cmdline *cl, 3776 __attribute__((unused)) void *data) 3777 { 3778 struct cmd_showport_result *res = parsed_result; 3779 if (!strcmp(res->show, "clear")) { 3780 if (!strcmp(res->what, "stats")) 3781 nic_stats_clear(res->portnum); 3782 } else if (!strcmp(res->what, "info")) 3783 port_infos_display(res->portnum); 3784 else if (!strcmp(res->what, "stats")) 3785 nic_stats_display(res->portnum); 3786 else if (!strcmp(res->what, "fdir")) 3787 fdir_get_infos(res->portnum); 3788 else if (!strcmp(res->what, "stat_qmap")) 3789 nic_stats_mapping_display(res->portnum); 3790 } 3791 3792 cmdline_parse_token_string_t cmd_showport_show = 3793 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show, 3794 "show#clear"); 3795 cmdline_parse_token_string_t cmd_showport_port = 3796 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port"); 3797 cmdline_parse_token_string_t cmd_showport_what = 3798 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what, 3799 "info#stats#fdir#stat_qmap"); 3800 cmdline_parse_token_num_t cmd_showport_portnum = 3801 TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, INT32); 3802 3803 cmdline_parse_inst_t cmd_showport = { 3804 .f = cmd_showport_parsed, 3805 .data = NULL, 3806 .help_str = "show|clear port info|stats|fdir|stat_qmap X (X = port number)", 3807 .tokens = { 3808 (void *)&cmd_showport_show, 3809 (void *)&cmd_showport_port, 3810 (void *)&cmd_showport_what, 3811 (void *)&cmd_showport_portnum, 3812 NULL, 3813 }, 3814 }; 3815 3816 /* *** READ PORT REGISTER *** */ 3817 struct cmd_read_reg_result { 3818 cmdline_fixed_string_t read; 3819 cmdline_fixed_string_t reg; 3820 uint8_t port_id; 3821 uint32_t reg_off; 3822 }; 3823 3824 static void 3825 cmd_read_reg_parsed(void *parsed_result, 3826 __attribute__((unused)) struct cmdline *cl, 3827 __attribute__((unused)) void *data) 3828 { 3829 struct cmd_read_reg_result *res = parsed_result; 3830 port_reg_display(res->port_id, res->reg_off); 3831 } 3832 3833 cmdline_parse_token_string_t cmd_read_reg_read = 3834 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read"); 3835 cmdline_parse_token_string_t cmd_read_reg_reg = 3836 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg"); 3837 cmdline_parse_token_num_t cmd_read_reg_port_id = 3838 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8); 3839 cmdline_parse_token_num_t cmd_read_reg_reg_off = 3840 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32); 3841 3842 cmdline_parse_inst_t cmd_read_reg = { 3843 .f = cmd_read_reg_parsed, 3844 .data = NULL, 3845 .help_str = "read reg port_id reg_off", 3846 .tokens = { 3847 (void *)&cmd_read_reg_read, 3848 (void *)&cmd_read_reg_reg, 3849 (void *)&cmd_read_reg_port_id, 3850 (void *)&cmd_read_reg_reg_off, 3851 NULL, 3852 }, 3853 }; 3854 3855 /* *** READ PORT REGISTER BIT FIELD *** */ 3856 struct cmd_read_reg_bit_field_result { 3857 cmdline_fixed_string_t read; 3858 cmdline_fixed_string_t regfield; 3859 uint8_t port_id; 3860 uint32_t reg_off; 3861 uint8_t bit1_pos; 3862 uint8_t bit2_pos; 3863 }; 3864 3865 static void 3866 cmd_read_reg_bit_field_parsed(void *parsed_result, 3867 __attribute__((unused)) struct cmdline *cl, 3868 __attribute__((unused)) void *data) 3869 { 3870 struct cmd_read_reg_bit_field_result *res = parsed_result; 3871 port_reg_bit_field_display(res->port_id, res->reg_off, 3872 res->bit1_pos, res->bit2_pos); 3873 } 3874 3875 cmdline_parse_token_string_t cmd_read_reg_bit_field_read = 3876 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read, 3877 "read"); 3878 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield = 3879 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, 3880 regfield, "regfield"); 3881 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id = 3882 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id, 3883 UINT8); 3884 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off = 3885 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off, 3886 UINT32); 3887 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos = 3888 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos, 3889 UINT8); 3890 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos = 3891 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos, 3892 UINT8); 3893 3894 cmdline_parse_inst_t cmd_read_reg_bit_field = { 3895 .f = cmd_read_reg_bit_field_parsed, 3896 .data = NULL, 3897 .help_str = "read regfield port_id reg_off bit_x bit_y " 3898 "(read register bit field between bit_x and bit_y included)", 3899 .tokens = { 3900 (void *)&cmd_read_reg_bit_field_read, 3901 (void *)&cmd_read_reg_bit_field_regfield, 3902 (void *)&cmd_read_reg_bit_field_port_id, 3903 (void *)&cmd_read_reg_bit_field_reg_off, 3904 (void *)&cmd_read_reg_bit_field_bit1_pos, 3905 (void *)&cmd_read_reg_bit_field_bit2_pos, 3906 NULL, 3907 }, 3908 }; 3909 3910 /* *** READ PORT REGISTER BIT *** */ 3911 struct cmd_read_reg_bit_result { 3912 cmdline_fixed_string_t read; 3913 cmdline_fixed_string_t regbit; 3914 uint8_t port_id; 3915 uint32_t reg_off; 3916 uint8_t bit_pos; 3917 }; 3918 3919 static void 3920 cmd_read_reg_bit_parsed(void *parsed_result, 3921 __attribute__((unused)) struct cmdline *cl, 3922 __attribute__((unused)) void *data) 3923 { 3924 struct cmd_read_reg_bit_result *res = parsed_result; 3925 port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos); 3926 } 3927 3928 cmdline_parse_token_string_t cmd_read_reg_bit_read = 3929 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read"); 3930 cmdline_parse_token_string_t cmd_read_reg_bit_regbit = 3931 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, 3932 regbit, "regbit"); 3933 cmdline_parse_token_num_t cmd_read_reg_bit_port_id = 3934 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8); 3935 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off = 3936 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32); 3937 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos = 3938 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8); 3939 3940 cmdline_parse_inst_t cmd_read_reg_bit = { 3941 .f = cmd_read_reg_bit_parsed, 3942 .data = NULL, 3943 .help_str = "read regbit port_id reg_off bit_x (0 <= bit_x <= 31)", 3944 .tokens = { 3945 (void *)&cmd_read_reg_bit_read, 3946 (void *)&cmd_read_reg_bit_regbit, 3947 (void *)&cmd_read_reg_bit_port_id, 3948 (void *)&cmd_read_reg_bit_reg_off, 3949 (void *)&cmd_read_reg_bit_bit_pos, 3950 NULL, 3951 }, 3952 }; 3953 3954 /* *** WRITE PORT REGISTER *** */ 3955 struct cmd_write_reg_result { 3956 cmdline_fixed_string_t write; 3957 cmdline_fixed_string_t reg; 3958 uint8_t port_id; 3959 uint32_t reg_off; 3960 uint32_t value; 3961 }; 3962 3963 static void 3964 cmd_write_reg_parsed(void *parsed_result, 3965 __attribute__((unused)) struct cmdline *cl, 3966 __attribute__((unused)) void *data) 3967 { 3968 struct cmd_write_reg_result *res = parsed_result; 3969 port_reg_set(res->port_id, res->reg_off, res->value); 3970 } 3971 3972 cmdline_parse_token_string_t cmd_write_reg_write = 3973 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write"); 3974 cmdline_parse_token_string_t cmd_write_reg_reg = 3975 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg"); 3976 cmdline_parse_token_num_t cmd_write_reg_port_id = 3977 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8); 3978 cmdline_parse_token_num_t cmd_write_reg_reg_off = 3979 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32); 3980 cmdline_parse_token_num_t cmd_write_reg_value = 3981 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32); 3982 3983 cmdline_parse_inst_t cmd_write_reg = { 3984 .f = cmd_write_reg_parsed, 3985 .data = NULL, 3986 .help_str = "write reg port_id reg_off reg_value", 3987 .tokens = { 3988 (void *)&cmd_write_reg_write, 3989 (void *)&cmd_write_reg_reg, 3990 (void *)&cmd_write_reg_port_id, 3991 (void *)&cmd_write_reg_reg_off, 3992 (void *)&cmd_write_reg_value, 3993 NULL, 3994 }, 3995 }; 3996 3997 /* *** WRITE PORT REGISTER BIT FIELD *** */ 3998 struct cmd_write_reg_bit_field_result { 3999 cmdline_fixed_string_t write; 4000 cmdline_fixed_string_t regfield; 4001 uint8_t port_id; 4002 uint32_t reg_off; 4003 uint8_t bit1_pos; 4004 uint8_t bit2_pos; 4005 uint32_t value; 4006 }; 4007 4008 static void 4009 cmd_write_reg_bit_field_parsed(void *parsed_result, 4010 __attribute__((unused)) struct cmdline *cl, 4011 __attribute__((unused)) void *data) 4012 { 4013 struct cmd_write_reg_bit_field_result *res = parsed_result; 4014 port_reg_bit_field_set(res->port_id, res->reg_off, 4015 res->bit1_pos, res->bit2_pos, res->value); 4016 } 4017 4018 cmdline_parse_token_string_t cmd_write_reg_bit_field_write = 4019 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write, 4020 "write"); 4021 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield = 4022 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, 4023 regfield, "regfield"); 4024 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id = 4025 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id, 4026 UINT8); 4027 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off = 4028 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off, 4029 UINT32); 4030 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos = 4031 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos, 4032 UINT8); 4033 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos = 4034 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos, 4035 UINT8); 4036 cmdline_parse_token_num_t cmd_write_reg_bit_field_value = 4037 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value, 4038 UINT32); 4039 4040 cmdline_parse_inst_t cmd_write_reg_bit_field = { 4041 .f = cmd_write_reg_bit_field_parsed, 4042 .data = NULL, 4043 .help_str = "write regfield port_id reg_off bit_x bit_y reg_value" 4044 "(set register bit field between bit_x and bit_y included)", 4045 .tokens = { 4046 (void *)&cmd_write_reg_bit_field_write, 4047 (void *)&cmd_write_reg_bit_field_regfield, 4048 (void *)&cmd_write_reg_bit_field_port_id, 4049 (void *)&cmd_write_reg_bit_field_reg_off, 4050 (void *)&cmd_write_reg_bit_field_bit1_pos, 4051 (void *)&cmd_write_reg_bit_field_bit2_pos, 4052 (void *)&cmd_write_reg_bit_field_value, 4053 NULL, 4054 }, 4055 }; 4056 4057 /* *** WRITE PORT REGISTER BIT *** */ 4058 struct cmd_write_reg_bit_result { 4059 cmdline_fixed_string_t write; 4060 cmdline_fixed_string_t regbit; 4061 uint8_t port_id; 4062 uint32_t reg_off; 4063 uint8_t bit_pos; 4064 uint8_t value; 4065 }; 4066 4067 static void 4068 cmd_write_reg_bit_parsed(void *parsed_result, 4069 __attribute__((unused)) struct cmdline *cl, 4070 __attribute__((unused)) void *data) 4071 { 4072 struct cmd_write_reg_bit_result *res = parsed_result; 4073 port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value); 4074 } 4075 4076 cmdline_parse_token_string_t cmd_write_reg_bit_write = 4077 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write, 4078 "write"); 4079 cmdline_parse_token_string_t cmd_write_reg_bit_regbit = 4080 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, 4081 regbit, "regbit"); 4082 cmdline_parse_token_num_t cmd_write_reg_bit_port_id = 4083 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8); 4084 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off = 4085 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32); 4086 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos = 4087 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8); 4088 cmdline_parse_token_num_t cmd_write_reg_bit_value = 4089 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8); 4090 4091 cmdline_parse_inst_t cmd_write_reg_bit = { 4092 .f = cmd_write_reg_bit_parsed, 4093 .data = NULL, 4094 .help_str = "write regbit port_id reg_off bit_x 0/1 (0 <= bit_x <= 31)", 4095 .tokens = { 4096 (void *)&cmd_write_reg_bit_write, 4097 (void *)&cmd_write_reg_bit_regbit, 4098 (void *)&cmd_write_reg_bit_port_id, 4099 (void *)&cmd_write_reg_bit_reg_off, 4100 (void *)&cmd_write_reg_bit_bit_pos, 4101 (void *)&cmd_write_reg_bit_value, 4102 NULL, 4103 }, 4104 }; 4105 4106 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */ 4107 struct cmd_read_rxd_txd_result { 4108 cmdline_fixed_string_t read; 4109 cmdline_fixed_string_t rxd_txd; 4110 uint8_t port_id; 4111 uint16_t queue_id; 4112 uint16_t desc_id; 4113 }; 4114 4115 static void 4116 cmd_read_rxd_txd_parsed(void *parsed_result, 4117 __attribute__((unused)) struct cmdline *cl, 4118 __attribute__((unused)) void *data) 4119 { 4120 struct cmd_read_rxd_txd_result *res = parsed_result; 4121 4122 if (!strcmp(res->rxd_txd, "rxd")) 4123 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id); 4124 else if (!strcmp(res->rxd_txd, "txd")) 4125 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id); 4126 } 4127 4128 cmdline_parse_token_string_t cmd_read_rxd_txd_read = 4129 TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read"); 4130 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd = 4131 TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd, 4132 "rxd#txd"); 4133 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id = 4134 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8); 4135 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id = 4136 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16); 4137 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id = 4138 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16); 4139 4140 cmdline_parse_inst_t cmd_read_rxd_txd = { 4141 .f = cmd_read_rxd_txd_parsed, 4142 .data = NULL, 4143 .help_str = "read rxd|txd port_id queue_id rxd_id", 4144 .tokens = { 4145 (void *)&cmd_read_rxd_txd_read, 4146 (void *)&cmd_read_rxd_txd_rxd_txd, 4147 (void *)&cmd_read_rxd_txd_port_id, 4148 (void *)&cmd_read_rxd_txd_queue_id, 4149 (void *)&cmd_read_rxd_txd_desc_id, 4150 NULL, 4151 }, 4152 }; 4153 4154 /* *** QUIT *** */ 4155 struct cmd_quit_result { 4156 cmdline_fixed_string_t quit; 4157 }; 4158 4159 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result, 4160 struct cmdline *cl, 4161 __attribute__((unused)) void *data) 4162 { 4163 pmd_test_exit(); 4164 cmdline_quit(cl); 4165 } 4166 4167 cmdline_parse_token_string_t cmd_quit_quit = 4168 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit"); 4169 4170 cmdline_parse_inst_t cmd_quit = { 4171 .f = cmd_quit_parsed, 4172 .data = NULL, 4173 .help_str = "exit application", 4174 .tokens = { 4175 (void *)&cmd_quit_quit, 4176 NULL, 4177 }, 4178 }; 4179 4180 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */ 4181 struct cmd_mac_addr_result { 4182 cmdline_fixed_string_t mac_addr_cmd; 4183 cmdline_fixed_string_t what; 4184 uint8_t port_num; 4185 struct ether_addr address; 4186 }; 4187 4188 static void cmd_mac_addr_parsed(void *parsed_result, 4189 __attribute__((unused)) struct cmdline *cl, 4190 __attribute__((unused)) void *data) 4191 { 4192 struct cmd_mac_addr_result *res = parsed_result; 4193 int ret; 4194 4195 if (strcmp(res->what, "add") == 0) 4196 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0); 4197 else 4198 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address); 4199 4200 /* check the return value and print it if is < 0 */ 4201 if(ret < 0) 4202 printf("mac_addr_cmd error: (%s)\n", strerror(-ret)); 4203 4204 } 4205 4206 cmdline_parse_token_string_t cmd_mac_addr_cmd = 4207 TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd, 4208 "mac_addr"); 4209 cmdline_parse_token_string_t cmd_mac_addr_what = 4210 TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what, 4211 "add#remove"); 4212 cmdline_parse_token_num_t cmd_mac_addr_portnum = 4213 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8); 4214 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr = 4215 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address); 4216 4217 cmdline_parse_inst_t cmd_mac_addr = { 4218 .f = cmd_mac_addr_parsed, 4219 .data = (void *)0, 4220 .help_str = "mac_addr add|remove X <address>: " 4221 "add/remove MAC address on port X", 4222 .tokens = { 4223 (void *)&cmd_mac_addr_cmd, 4224 (void *)&cmd_mac_addr_what, 4225 (void *)&cmd_mac_addr_portnum, 4226 (void *)&cmd_mac_addr_addr, 4227 NULL, 4228 }, 4229 }; 4230 4231 4232 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */ 4233 struct cmd_set_qmap_result { 4234 cmdline_fixed_string_t set; 4235 cmdline_fixed_string_t qmap; 4236 cmdline_fixed_string_t what; 4237 uint8_t port_id; 4238 uint16_t queue_id; 4239 uint8_t map_value; 4240 }; 4241 4242 static void 4243 cmd_set_qmap_parsed(void *parsed_result, 4244 __attribute__((unused)) struct cmdline *cl, 4245 __attribute__((unused)) void *data) 4246 { 4247 struct cmd_set_qmap_result *res = parsed_result; 4248 int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1; 4249 4250 set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value); 4251 } 4252 4253 cmdline_parse_token_string_t cmd_setqmap_set = 4254 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result, 4255 set, "set"); 4256 cmdline_parse_token_string_t cmd_setqmap_qmap = 4257 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result, 4258 qmap, "stat_qmap"); 4259 cmdline_parse_token_string_t cmd_setqmap_what = 4260 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result, 4261 what, "tx#rx"); 4262 cmdline_parse_token_num_t cmd_setqmap_portid = 4263 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, 4264 port_id, UINT8); 4265 cmdline_parse_token_num_t cmd_setqmap_queueid = 4266 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, 4267 queue_id, UINT16); 4268 cmdline_parse_token_num_t cmd_setqmap_mapvalue = 4269 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, 4270 map_value, UINT8); 4271 4272 cmdline_parse_inst_t cmd_set_qmap = { 4273 .f = cmd_set_qmap_parsed, 4274 .data = NULL, 4275 .help_str = "Set statistics mapping value on tx|rx queue_id of port_id", 4276 .tokens = { 4277 (void *)&cmd_setqmap_set, 4278 (void *)&cmd_setqmap_qmap, 4279 (void *)&cmd_setqmap_what, 4280 (void *)&cmd_setqmap_portid, 4281 (void *)&cmd_setqmap_queueid, 4282 (void *)&cmd_setqmap_mapvalue, 4283 NULL, 4284 }, 4285 }; 4286 4287 /* *** CONFIGURE UNICAST HASH TABLE *** */ 4288 struct cmd_set_uc_hash_table { 4289 cmdline_fixed_string_t set; 4290 cmdline_fixed_string_t port; 4291 uint8_t port_id; 4292 cmdline_fixed_string_t what; 4293 struct ether_addr address; 4294 cmdline_fixed_string_t mode; 4295 }; 4296 4297 static void 4298 cmd_set_uc_hash_parsed(void *parsed_result, 4299 __attribute__((unused)) struct cmdline *cl, 4300 __attribute__((unused)) void *data) 4301 { 4302 int ret=0; 4303 struct cmd_set_uc_hash_table *res = parsed_result; 4304 4305 int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 4306 4307 if (strcmp(res->what, "uta") == 0) 4308 ret = rte_eth_dev_uc_hash_table_set(res->port_id, 4309 &res->address,(uint8_t)is_on); 4310 if (ret < 0) 4311 printf("bad unicast hash table parameter, return code = %d \n", ret); 4312 4313 } 4314 4315 cmdline_parse_token_string_t cmd_set_uc_hash_set = 4316 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 4317 set, "set"); 4318 cmdline_parse_token_string_t cmd_set_uc_hash_port = 4319 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 4320 port, "port"); 4321 cmdline_parse_token_num_t cmd_set_uc_hash_portid = 4322 TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table, 4323 port_id, UINT8); 4324 cmdline_parse_token_string_t cmd_set_uc_hash_what = 4325 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 4326 what, "uta"); 4327 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac = 4328 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table, 4329 address); 4330 cmdline_parse_token_string_t cmd_set_uc_hash_mode = 4331 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 4332 mode, "on#off"); 4333 4334 cmdline_parse_inst_t cmd_set_uc_hash_filter = { 4335 .f = cmd_set_uc_hash_parsed, 4336 .data = NULL, 4337 .help_str = "set port X uta Y on|off(X = port number,Y = MAC address)", 4338 .tokens = { 4339 (void *)&cmd_set_uc_hash_set, 4340 (void *)&cmd_set_uc_hash_port, 4341 (void *)&cmd_set_uc_hash_portid, 4342 (void *)&cmd_set_uc_hash_what, 4343 (void *)&cmd_set_uc_hash_mac, 4344 (void *)&cmd_set_uc_hash_mode, 4345 NULL, 4346 }, 4347 }; 4348 4349 struct cmd_set_uc_all_hash_table { 4350 cmdline_fixed_string_t set; 4351 cmdline_fixed_string_t port; 4352 uint8_t port_id; 4353 cmdline_fixed_string_t what; 4354 cmdline_fixed_string_t value; 4355 cmdline_fixed_string_t mode; 4356 }; 4357 4358 static void 4359 cmd_set_uc_all_hash_parsed(void *parsed_result, 4360 __attribute__((unused)) struct cmdline *cl, 4361 __attribute__((unused)) void *data) 4362 { 4363 int ret=0; 4364 struct cmd_set_uc_all_hash_table *res = parsed_result; 4365 4366 int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 4367 4368 if ((strcmp(res->what, "uta") == 0) && 4369 (strcmp(res->value, "all") == 0)) 4370 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on); 4371 if (ret < 0) 4372 printf("bad unicast hash table parameter," 4373 "return code = %d \n", ret); 4374 } 4375 4376 cmdline_parse_token_string_t cmd_set_uc_all_hash_set = 4377 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 4378 set, "set"); 4379 cmdline_parse_token_string_t cmd_set_uc_all_hash_port = 4380 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 4381 port, "port"); 4382 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid = 4383 TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table, 4384 port_id, UINT8); 4385 cmdline_parse_token_string_t cmd_set_uc_all_hash_what = 4386 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 4387 what, "uta"); 4388 cmdline_parse_token_string_t cmd_set_uc_all_hash_value = 4389 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 4390 value,"all"); 4391 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode = 4392 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 4393 mode, "on#off"); 4394 4395 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = { 4396 .f = cmd_set_uc_all_hash_parsed, 4397 .data = NULL, 4398 .help_str = "set port X uta all on|off (X = port number)", 4399 .tokens = { 4400 (void *)&cmd_set_uc_all_hash_set, 4401 (void *)&cmd_set_uc_all_hash_port, 4402 (void *)&cmd_set_uc_all_hash_portid, 4403 (void *)&cmd_set_uc_all_hash_what, 4404 (void *)&cmd_set_uc_all_hash_value, 4405 (void *)&cmd_set_uc_all_hash_mode, 4406 NULL, 4407 }, 4408 }; 4409 4410 /* *** CONFIGURE VF TRAFFIC CONTROL *** */ 4411 struct cmd_set_vf_traffic { 4412 cmdline_fixed_string_t set; 4413 cmdline_fixed_string_t port; 4414 uint8_t port_id; 4415 cmdline_fixed_string_t vf; 4416 uint8_t vf_id; 4417 cmdline_fixed_string_t what; 4418 cmdline_fixed_string_t mode; 4419 }; 4420 4421 static void 4422 cmd_set_vf_traffic_parsed(void *parsed_result, 4423 __attribute__((unused)) struct cmdline *cl, 4424 __attribute__((unused)) void *data) 4425 { 4426 struct cmd_set_vf_traffic *res = parsed_result; 4427 int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0; 4428 int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 4429 4430 set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on); 4431 } 4432 4433 cmdline_parse_token_string_t cmd_setvf_traffic_set = 4434 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 4435 set, "set"); 4436 cmdline_parse_token_string_t cmd_setvf_traffic_port = 4437 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 4438 port, "port"); 4439 cmdline_parse_token_num_t cmd_setvf_traffic_portid = 4440 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic, 4441 port_id, UINT8); 4442 cmdline_parse_token_string_t cmd_setvf_traffic_vf = 4443 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 4444 vf, "vf"); 4445 cmdline_parse_token_num_t cmd_setvf_traffic_vfid = 4446 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic, 4447 vf_id, UINT8); 4448 cmdline_parse_token_string_t cmd_setvf_traffic_what = 4449 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 4450 what, "tx#rx"); 4451 cmdline_parse_token_string_t cmd_setvf_traffic_mode = 4452 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 4453 mode, "on#off"); 4454 4455 cmdline_parse_inst_t cmd_set_vf_traffic = { 4456 .f = cmd_set_vf_traffic_parsed, 4457 .data = NULL, 4458 .help_str = "set port X vf Y rx|tx on|off (X = port number,Y = vf id)", 4459 .tokens = { 4460 (void *)&cmd_setvf_traffic_set, 4461 (void *)&cmd_setvf_traffic_port, 4462 (void *)&cmd_setvf_traffic_portid, 4463 (void *)&cmd_setvf_traffic_vf, 4464 (void *)&cmd_setvf_traffic_vfid, 4465 (void *)&cmd_setvf_traffic_what, 4466 (void *)&cmd_setvf_traffic_mode, 4467 NULL, 4468 }, 4469 }; 4470 4471 /* *** CONFIGURE VF RECEIVE MODE *** */ 4472 struct cmd_set_vf_rxmode { 4473 cmdline_fixed_string_t set; 4474 cmdline_fixed_string_t port; 4475 uint8_t port_id; 4476 cmdline_fixed_string_t vf; 4477 uint8_t vf_id; 4478 cmdline_fixed_string_t what; 4479 cmdline_fixed_string_t mode; 4480 cmdline_fixed_string_t on; 4481 }; 4482 4483 static void 4484 cmd_set_vf_rxmode_parsed(void *parsed_result, 4485 __attribute__((unused)) struct cmdline *cl, 4486 __attribute__((unused)) void *data) 4487 { 4488 int ret; 4489 uint16_t rx_mode = 0; 4490 struct cmd_set_vf_rxmode *res = parsed_result; 4491 4492 int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0; 4493 if (!strcmp(res->what,"rxmode")) { 4494 if (!strcmp(res->mode, "AUPE")) 4495 rx_mode |= ETH_VMDQ_ACCEPT_UNTAG; 4496 else if (!strcmp(res->mode, "ROPE")) 4497 rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC; 4498 else if (!strcmp(res->mode, "BAM")) 4499 rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST; 4500 else if (!strncmp(res->mode, "MPE",3)) 4501 rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST; 4502 } 4503 4504 ret = rte_eth_dev_set_vf_rxmode(res->port_id,res->vf_id,rx_mode,(uint8_t)is_on); 4505 if (ret < 0) 4506 printf("bad VF receive mode parameter, return code = %d \n", 4507 ret); 4508 } 4509 4510 cmdline_parse_token_string_t cmd_set_vf_rxmode_set = 4511 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 4512 set, "set"); 4513 cmdline_parse_token_string_t cmd_set_vf_rxmode_port = 4514 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 4515 port, "port"); 4516 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid = 4517 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode, 4518 port_id, UINT8); 4519 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf = 4520 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 4521 vf, "vf"); 4522 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid = 4523 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode, 4524 vf_id, UINT8); 4525 cmdline_parse_token_string_t cmd_set_vf_rxmode_what = 4526 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 4527 what, "rxmode"); 4528 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode = 4529 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 4530 mode, "AUPE#ROPE#BAM#MPE"); 4531 cmdline_parse_token_string_t cmd_set_vf_rxmode_on = 4532 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 4533 on, "on#off"); 4534 4535 cmdline_parse_inst_t cmd_set_vf_rxmode = { 4536 .f = cmd_set_vf_rxmode_parsed, 4537 .data = NULL, 4538 .help_str = "set port X vf Y rxmode AUPE|ROPE|BAM|MPE on|off", 4539 .tokens = { 4540 (void *)&cmd_set_vf_rxmode_set, 4541 (void *)&cmd_set_vf_rxmode_port, 4542 (void *)&cmd_set_vf_rxmode_portid, 4543 (void *)&cmd_set_vf_rxmode_vf, 4544 (void *)&cmd_set_vf_rxmode_vfid, 4545 (void *)&cmd_set_vf_rxmode_what, 4546 (void *)&cmd_set_vf_rxmode_mode, 4547 (void *)&cmd_set_vf_rxmode_on, 4548 NULL, 4549 }, 4550 }; 4551 4552 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */ 4553 struct cmd_vf_mac_addr_result { 4554 cmdline_fixed_string_t mac_addr_cmd; 4555 cmdline_fixed_string_t what; 4556 cmdline_fixed_string_t port; 4557 uint8_t port_num; 4558 cmdline_fixed_string_t vf; 4559 uint8_t vf_num; 4560 struct ether_addr address; 4561 }; 4562 4563 static void cmd_vf_mac_addr_parsed(void *parsed_result, 4564 __attribute__((unused)) struct cmdline *cl, 4565 __attribute__((unused)) void *data) 4566 { 4567 struct cmd_vf_mac_addr_result *res = parsed_result; 4568 int ret = 0; 4569 4570 if (strcmp(res->what, "add") == 0) 4571 ret = rte_eth_dev_mac_addr_add(res->port_num, 4572 &res->address, res->vf_num); 4573 if(ret < 0) 4574 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret)); 4575 4576 } 4577 4578 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd = 4579 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 4580 mac_addr_cmd,"mac_addr"); 4581 cmdline_parse_token_string_t cmd_vf_mac_addr_what = 4582 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 4583 what,"add"); 4584 cmdline_parse_token_string_t cmd_vf_mac_addr_port = 4585 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 4586 port,"port"); 4587 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum = 4588 TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result, 4589 port_num, UINT8); 4590 cmdline_parse_token_string_t cmd_vf_mac_addr_vf = 4591 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 4592 vf,"vf"); 4593 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum = 4594 TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result, 4595 vf_num, UINT8); 4596 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr = 4597 TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result, 4598 address); 4599 4600 cmdline_parse_inst_t cmd_vf_mac_addr_filter = { 4601 .f = cmd_vf_mac_addr_parsed, 4602 .data = (void *)0, 4603 .help_str = "mac_addr add port X vf Y ethaddr:(X = port number," 4604 "Y = VF number)add MAC address filtering for a VF on port X", 4605 .tokens = { 4606 (void *)&cmd_vf_mac_addr_cmd, 4607 (void *)&cmd_vf_mac_addr_what, 4608 (void *)&cmd_vf_mac_addr_port, 4609 (void *)&cmd_vf_mac_addr_portnum, 4610 (void *)&cmd_vf_mac_addr_vf, 4611 (void *)&cmd_vf_mac_addr_vfnum, 4612 (void *)&cmd_vf_mac_addr_addr, 4613 NULL, 4614 }, 4615 }; 4616 4617 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */ 4618 struct cmd_vf_rx_vlan_filter { 4619 cmdline_fixed_string_t rx_vlan; 4620 cmdline_fixed_string_t what; 4621 uint16_t vlan_id; 4622 cmdline_fixed_string_t port; 4623 uint8_t port_id; 4624 cmdline_fixed_string_t vf; 4625 uint64_t vf_mask; 4626 }; 4627 4628 static void 4629 cmd_vf_rx_vlan_filter_parsed(void *parsed_result, 4630 __attribute__((unused)) struct cmdline *cl, 4631 __attribute__((unused)) void *data) 4632 { 4633 struct cmd_vf_rx_vlan_filter *res = parsed_result; 4634 4635 if (!strcmp(res->what, "add")) 4636 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 1); 4637 else 4638 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 0); 4639 } 4640 4641 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan = 4642 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 4643 rx_vlan, "rx_vlan"); 4644 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what = 4645 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 4646 what, "add#rm"); 4647 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid = 4648 TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter, 4649 vlan_id, UINT16); 4650 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port = 4651 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 4652 port, "port"); 4653 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid = 4654 TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter, 4655 port_id, UINT8); 4656 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf = 4657 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 4658 vf, "vf"); 4659 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask = 4660 TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter, 4661 vf_mask, UINT64); 4662 4663 cmdline_parse_inst_t cmd_vf_rxvlan_filter = { 4664 .f = cmd_vf_rx_vlan_filter_parsed, 4665 .data = NULL, 4666 .help_str = "rx_vlan add|rm X port Y vf Z (X = VLAN ID," 4667 "Y = port number,Z = hexadecimal VF mask)", 4668 .tokens = { 4669 (void *)&cmd_vf_rx_vlan_filter_rx_vlan, 4670 (void *)&cmd_vf_rx_vlan_filter_what, 4671 (void *)&cmd_vf_rx_vlan_filter_vlanid, 4672 (void *)&cmd_vf_rx_vlan_filter_port, 4673 (void *)&cmd_vf_rx_vlan_filter_portid, 4674 (void *)&cmd_vf_rx_vlan_filter_vf, 4675 (void *)&cmd_vf_rx_vlan_filter_vf_mask, 4676 NULL, 4677 }, 4678 }; 4679 4680 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */ 4681 struct cmd_set_mirror_mask_result { 4682 cmdline_fixed_string_t set; 4683 cmdline_fixed_string_t port; 4684 uint8_t port_id; 4685 cmdline_fixed_string_t mirror; 4686 uint8_t rule_id; 4687 cmdline_fixed_string_t what; 4688 cmdline_fixed_string_t value; 4689 cmdline_fixed_string_t dstpool; 4690 uint8_t dstpool_id; 4691 cmdline_fixed_string_t on; 4692 }; 4693 4694 cmdline_parse_token_string_t cmd_mirror_mask_set = 4695 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 4696 set, "set"); 4697 cmdline_parse_token_string_t cmd_mirror_mask_port = 4698 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 4699 port, "port"); 4700 cmdline_parse_token_string_t cmd_mirror_mask_portid = 4701 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result, 4702 port_id, UINT8); 4703 cmdline_parse_token_string_t cmd_mirror_mask_mirror = 4704 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 4705 mirror, "mirror-rule"); 4706 cmdline_parse_token_num_t cmd_mirror_mask_ruleid = 4707 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result, 4708 rule_id, UINT8); 4709 cmdline_parse_token_string_t cmd_mirror_mask_what = 4710 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 4711 what, "pool-mirror#vlan-mirror"); 4712 cmdline_parse_token_string_t cmd_mirror_mask_value = 4713 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 4714 value, NULL); 4715 cmdline_parse_token_string_t cmd_mirror_mask_dstpool = 4716 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 4717 dstpool, "dst-pool"); 4718 cmdline_parse_token_num_t cmd_mirror_mask_poolid = 4719 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result, 4720 dstpool_id, UINT8); 4721 cmdline_parse_token_string_t cmd_mirror_mask_on = 4722 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 4723 on, "on#off"); 4724 4725 static void 4726 cmd_set_mirror_mask_parsed(void *parsed_result, 4727 __attribute__((unused)) struct cmdline *cl, 4728 __attribute__((unused)) void *data) 4729 { 4730 int ret,nb_item,i; 4731 struct cmd_set_mirror_mask_result *res = parsed_result; 4732 struct rte_eth_vmdq_mirror_conf mr_conf; 4733 4734 memset(&mr_conf,0,sizeof(struct rte_eth_vmdq_mirror_conf)); 4735 4736 unsigned int vlan_list[ETH_VMDQ_MAX_VLAN_FILTERS]; 4737 4738 mr_conf.dst_pool = res->dstpool_id; 4739 4740 if (!strcmp(res->what, "pool-mirror")) { 4741 mr_conf.pool_mask = strtoull(res->value,NULL,16); 4742 mr_conf.rule_type_mask = ETH_VMDQ_POOL_MIRROR; 4743 } else if(!strcmp(res->what, "vlan-mirror")) { 4744 mr_conf.rule_type_mask = ETH_VMDQ_VLAN_MIRROR; 4745 nb_item = parse_item_list(res->value, "core", 4746 ETH_VMDQ_MAX_VLAN_FILTERS,vlan_list,1); 4747 if (nb_item <= 0) 4748 return; 4749 4750 for(i=0; i < nb_item; i++) { 4751 if (vlan_list[i] > ETHER_MAX_VLAN_ID) { 4752 printf("Invalid vlan_id: must be < 4096\n"); 4753 return; 4754 } 4755 4756 mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i]; 4757 mr_conf.vlan.vlan_mask |= 1ULL << i; 4758 } 4759 } 4760 4761 if(!strcmp(res->on, "on")) 4762 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf, 4763 res->rule_id, 1); 4764 else 4765 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf, 4766 res->rule_id, 0); 4767 if(ret < 0) 4768 printf("mirror rule add error: (%s)\n", strerror(-ret)); 4769 } 4770 4771 cmdline_parse_inst_t cmd_set_mirror_mask = { 4772 .f = cmd_set_mirror_mask_parsed, 4773 .data = NULL, 4774 .help_str = "set port X mirror-rule Y pool-mirror|vlan-mirror " 4775 "pool_mask|vlan_id[,vlan_id]* dst-pool Z on|off", 4776 .tokens = { 4777 (void *)&cmd_mirror_mask_set, 4778 (void *)&cmd_mirror_mask_port, 4779 (void *)&cmd_mirror_mask_portid, 4780 (void *)&cmd_mirror_mask_mirror, 4781 (void *)&cmd_mirror_mask_ruleid, 4782 (void *)&cmd_mirror_mask_what, 4783 (void *)&cmd_mirror_mask_value, 4784 (void *)&cmd_mirror_mask_dstpool, 4785 (void *)&cmd_mirror_mask_poolid, 4786 (void *)&cmd_mirror_mask_on, 4787 NULL, 4788 }, 4789 }; 4790 4791 /* *** CONFIGURE VM MIRROR UDLINK/DOWNLINK RULE *** */ 4792 struct cmd_set_mirror_link_result { 4793 cmdline_fixed_string_t set; 4794 cmdline_fixed_string_t port; 4795 uint8_t port_id; 4796 cmdline_fixed_string_t mirror; 4797 uint8_t rule_id; 4798 cmdline_fixed_string_t what; 4799 cmdline_fixed_string_t dstpool; 4800 uint8_t dstpool_id; 4801 cmdline_fixed_string_t on; 4802 }; 4803 4804 cmdline_parse_token_string_t cmd_mirror_link_set = 4805 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 4806 set, "set"); 4807 cmdline_parse_token_string_t cmd_mirror_link_port = 4808 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 4809 port, "port"); 4810 cmdline_parse_token_string_t cmd_mirror_link_portid = 4811 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result, 4812 port_id, UINT8); 4813 cmdline_parse_token_string_t cmd_mirror_link_mirror = 4814 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 4815 mirror, "mirror-rule"); 4816 cmdline_parse_token_num_t cmd_mirror_link_ruleid = 4817 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result, 4818 rule_id, UINT8); 4819 cmdline_parse_token_string_t cmd_mirror_link_what = 4820 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 4821 what, "uplink-mirror#downlink-mirror"); 4822 cmdline_parse_token_string_t cmd_mirror_link_dstpool = 4823 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 4824 dstpool, "dst-pool"); 4825 cmdline_parse_token_num_t cmd_mirror_link_poolid = 4826 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result, 4827 dstpool_id, UINT8); 4828 cmdline_parse_token_string_t cmd_mirror_link_on = 4829 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 4830 on, "on#off"); 4831 4832 static void 4833 cmd_set_mirror_link_parsed(void *parsed_result, 4834 __attribute__((unused)) struct cmdline *cl, 4835 __attribute__((unused)) void *data) 4836 { 4837 int ret; 4838 struct cmd_set_mirror_link_result *res = parsed_result; 4839 struct rte_eth_vmdq_mirror_conf mr_conf; 4840 4841 memset(&mr_conf,0,sizeof(struct rte_eth_vmdq_mirror_conf)); 4842 if(!strcmp(res->what, "uplink-mirror")) { 4843 mr_conf.rule_type_mask = ETH_VMDQ_UPLINK_MIRROR; 4844 }else if(!strcmp(res->what, "downlink-mirror")) 4845 mr_conf.rule_type_mask = ETH_VMDQ_DOWNLIN_MIRROR; 4846 4847 mr_conf.dst_pool = res->dstpool_id; 4848 4849 if(!strcmp(res->on, "on")) 4850 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf, 4851 res->rule_id, 1); 4852 else 4853 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf, 4854 res->rule_id, 0); 4855 4856 /* check the return value and print it if is < 0 */ 4857 if(ret < 0) 4858 printf("mirror rule add error: (%s)\n", strerror(-ret)); 4859 4860 } 4861 4862 cmdline_parse_inst_t cmd_set_mirror_link = { 4863 .f = cmd_set_mirror_link_parsed, 4864 .data = NULL, 4865 .help_str = "set port X mirror-rule Y uplink-mirror|" 4866 "downlink-mirror dst-pool Z on|off", 4867 .tokens = { 4868 (void *)&cmd_mirror_link_set, 4869 (void *)&cmd_mirror_link_port, 4870 (void *)&cmd_mirror_link_portid, 4871 (void *)&cmd_mirror_link_mirror, 4872 (void *)&cmd_mirror_link_ruleid, 4873 (void *)&cmd_mirror_link_what, 4874 (void *)&cmd_mirror_link_dstpool, 4875 (void *)&cmd_mirror_link_poolid, 4876 (void *)&cmd_mirror_link_on, 4877 NULL, 4878 }, 4879 }; 4880 4881 /* *** RESET VM MIRROR RULE *** */ 4882 struct cmd_rm_mirror_rule_result { 4883 cmdline_fixed_string_t reset; 4884 cmdline_fixed_string_t port; 4885 uint8_t port_id; 4886 cmdline_fixed_string_t mirror; 4887 uint8_t rule_id; 4888 }; 4889 4890 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset = 4891 TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result, 4892 reset, "reset"); 4893 cmdline_parse_token_string_t cmd_rm_mirror_rule_port = 4894 TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result, 4895 port, "port"); 4896 cmdline_parse_token_string_t cmd_rm_mirror_rule_portid = 4897 TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result, 4898 port_id, UINT8); 4899 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror = 4900 TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result, 4901 mirror, "mirror-rule"); 4902 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid = 4903 TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result, 4904 rule_id, UINT8); 4905 4906 static void 4907 cmd_reset_mirror_rule_parsed(void *parsed_result, 4908 __attribute__((unused)) struct cmdline *cl, 4909 __attribute__((unused)) void *data) 4910 { 4911 int ret; 4912 struct cmd_set_mirror_link_result *res = parsed_result; 4913 /* check rule_id */ 4914 ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id); 4915 if(ret < 0) 4916 printf("mirror rule remove error: (%s)\n", strerror(-ret)); 4917 } 4918 4919 cmdline_parse_inst_t cmd_reset_mirror_rule = { 4920 .f = cmd_reset_mirror_rule_parsed, 4921 .data = NULL, 4922 .help_str = "reset port X mirror-rule Y", 4923 .tokens = { 4924 (void *)&cmd_rm_mirror_rule_reset, 4925 (void *)&cmd_rm_mirror_rule_port, 4926 (void *)&cmd_rm_mirror_rule_portid, 4927 (void *)&cmd_rm_mirror_rule_mirror, 4928 (void *)&cmd_rm_mirror_rule_ruleid, 4929 NULL, 4930 }, 4931 }; 4932 4933 /* ******************************************************************************** */ 4934 4935 /* list of instructions */ 4936 cmdline_parse_ctx_t main_ctx[] = { 4937 (cmdline_parse_inst_t *)&cmd_help_brief, 4938 (cmdline_parse_inst_t *)&cmd_help_long, 4939 (cmdline_parse_inst_t *)&cmd_quit, 4940 (cmdline_parse_inst_t *)&cmd_showport, 4941 (cmdline_parse_inst_t *)&cmd_showportall, 4942 (cmdline_parse_inst_t *)&cmd_showcfg, 4943 (cmdline_parse_inst_t *)&cmd_start, 4944 (cmdline_parse_inst_t *)&cmd_start_tx_first, 4945 (cmdline_parse_inst_t *)&cmd_reset, 4946 (cmdline_parse_inst_t *)&cmd_set_numbers, 4947 (cmdline_parse_inst_t *)&cmd_set_txpkts, 4948 (cmdline_parse_inst_t *)&cmd_set_fwd_list, 4949 (cmdline_parse_inst_t *)&cmd_set_fwd_mask, 4950 (cmdline_parse_inst_t *)&cmd_set_fwd_mode, 4951 (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one, 4952 (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all, 4953 (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one, 4954 (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all, 4955 (cmdline_parse_inst_t *)&cmd_set_flush_rx, 4956 #ifdef RTE_NIC_BYPASS 4957 (cmdline_parse_inst_t *)&cmd_set_bypass_mode, 4958 (cmdline_parse_inst_t *)&cmd_set_bypass_event, 4959 (cmdline_parse_inst_t *)&cmd_set_bypass_timeout, 4960 (cmdline_parse_inst_t *)&cmd_show_bypass_config, 4961 #endif 4962 (cmdline_parse_inst_t *)&cmd_vlan_offload, 4963 (cmdline_parse_inst_t *)&cmd_vlan_tpid, 4964 (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all, 4965 (cmdline_parse_inst_t *)&cmd_rx_vlan_filter, 4966 (cmdline_parse_inst_t *)&cmd_tx_vlan_set, 4967 (cmdline_parse_inst_t *)&cmd_tx_vlan_reset, 4968 (cmdline_parse_inst_t *)&cmd_tx_cksum_set, 4969 (cmdline_parse_inst_t *)&cmd_link_flow_control_set, 4970 (cmdline_parse_inst_t *)&cmd_priority_flow_control_set, 4971 (cmdline_parse_inst_t *)&cmd_config_dcb, 4972 (cmdline_parse_inst_t *)&cmd_read_reg, 4973 (cmdline_parse_inst_t *)&cmd_read_reg_bit_field, 4974 (cmdline_parse_inst_t *)&cmd_read_reg_bit, 4975 (cmdline_parse_inst_t *)&cmd_write_reg, 4976 (cmdline_parse_inst_t *)&cmd_write_reg_bit_field, 4977 (cmdline_parse_inst_t *)&cmd_write_reg_bit, 4978 (cmdline_parse_inst_t *)&cmd_read_rxd_txd, 4979 (cmdline_parse_inst_t *)&cmd_add_signature_filter, 4980 (cmdline_parse_inst_t *)&cmd_upd_signature_filter, 4981 (cmdline_parse_inst_t *)&cmd_rm_signature_filter, 4982 (cmdline_parse_inst_t *)&cmd_add_perfect_filter, 4983 (cmdline_parse_inst_t *)&cmd_upd_perfect_filter, 4984 (cmdline_parse_inst_t *)&cmd_rm_perfect_filter, 4985 (cmdline_parse_inst_t *)&cmd_set_masks_filter, 4986 (cmdline_parse_inst_t *)&cmd_set_ipv6_masks_filter, 4987 (cmdline_parse_inst_t *)&cmd_stop, 4988 (cmdline_parse_inst_t *)&cmd_mac_addr, 4989 (cmdline_parse_inst_t *)&cmd_set_qmap, 4990 (cmdline_parse_inst_t *)&cmd_operate_port, 4991 (cmdline_parse_inst_t *)&cmd_operate_specific_port, 4992 (cmdline_parse_inst_t *)&cmd_config_speed_all, 4993 (cmdline_parse_inst_t *)&cmd_config_speed_specific, 4994 (cmdline_parse_inst_t *)&cmd_config_rx_tx, 4995 (cmdline_parse_inst_t *)&cmd_config_max_pkt_len, 4996 (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag, 4997 (cmdline_parse_inst_t *)&cmd_config_rss, 4998 (cmdline_parse_inst_t *)&cmd_config_rss_reta, 4999 (cmdline_parse_inst_t *)&cmd_showport_reta, 5000 (cmdline_parse_inst_t *)&cmd_config_burst, 5001 (cmdline_parse_inst_t *)&cmd_config_thresh, 5002 (cmdline_parse_inst_t *)&cmd_config_threshold, 5003 (cmdline_parse_inst_t *)&cmd_set_vf_rxmode, 5004 (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter, 5005 (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter, 5006 (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter , 5007 (cmdline_parse_inst_t *)&cmd_set_vf_traffic, 5008 (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter, 5009 (cmdline_parse_inst_t *)&cmd_set_mirror_mask, 5010 (cmdline_parse_inst_t *)&cmd_set_mirror_link, 5011 (cmdline_parse_inst_t *)&cmd_reset_mirror_rule, 5012 NULL, 5013 }; 5014 5015 /* prompt function, called from main on MASTER lcore */ 5016 void 5017 prompt(void) 5018 { 5019 struct cmdline *cl; 5020 5021 cl = cmdline_stdin_new(main_ctx, "testpmd> "); 5022 if (cl == NULL) { 5023 return; 5024 } 5025 cmdline_interact(cl); 5026 cmdline_stdin_exit(cl); 5027 } 5028 5029 static void 5030 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue) 5031 { 5032 if (id < nb_ports) { 5033 /* check if need_reconfig has been set to 1 */ 5034 if (ports[id].need_reconfig == 0) 5035 ports[id].need_reconfig = dev; 5036 /* check if need_reconfig_queues has been set to 1 */ 5037 if (ports[id].need_reconfig_queues == 0) 5038 ports[id].need_reconfig_queues = queue; 5039 } else { 5040 portid_t pid; 5041 5042 for (pid = 0; pid < nb_ports; pid++) { 5043 /* check if need_reconfig has been set to 1 */ 5044 if (ports[pid].need_reconfig == 0) 5045 ports[pid].need_reconfig = dev; 5046 /* check if need_reconfig_queues has been set to 1 */ 5047 if (ports[pid].need_reconfig_queues == 0) 5048 ports[pid].need_reconfig_queues = queue; 5049 } 5050 } 5051 } 5052 5053 #ifdef RTE_NIC_BYPASS 5054 uint8_t 5055 bypass_is_supported(portid_t port_id) 5056 { 5057 struct rte_port *port; 5058 struct rte_pci_id *pci_id; 5059 5060 if (port_id >= nb_ports) { 5061 printf("\tPort id must be less than %d.\n", nb_ports); 5062 return 0; 5063 } 5064 5065 /* Get the device id. */ 5066 port = &ports[port_id]; 5067 pci_id = &port->dev_info.pci_dev->id; 5068 5069 /* Check if NIC supports bypass. */ 5070 if (pci_id->device_id == IXGBE_DEV_ID_82599_BYPASS) { 5071 return 1; 5072 } 5073 else { 5074 printf("\tBypass not supported for port_id = %d.\n", port_id); 5075 return 0; 5076 } 5077 } 5078 #endif 5079