1 /*- 2 * BSD LICENSE 3 * 4 * Copyright(c) 2010-2016 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 <stdio.h> 35 #include <stdlib.h> 36 #include <string.h> 37 #include <stdint.h> 38 #include <inttypes.h> 39 #include <sys/types.h> 40 #include <sys/queue.h> 41 #include <netinet/in.h> 42 #include <setjmp.h> 43 #include <stdarg.h> 44 #include <ctype.h> 45 #include <errno.h> 46 #include <getopt.h> 47 48 #include <rte_common.h> 49 #include <rte_log.h> 50 #include <rte_malloc.h> 51 #include <rte_memory.h> 52 #include <rte_memcpy.h> 53 #include <rte_eal.h> 54 #include <rte_launch.h> 55 #include <rte_atomic.h> 56 #include <rte_cycles.h> 57 #include <rte_prefetch.h> 58 #include <rte_lcore.h> 59 #include <rte_per_lcore.h> 60 #include <rte_branch_prediction.h> 61 #include <rte_interrupts.h> 62 #include <rte_pci.h> 63 #include <rte_random.h> 64 #include <rte_debug.h> 65 #include <rte_ether.h> 66 #include <rte_ethdev.h> 67 #include <rte_mempool.h> 68 #include <rte_mbuf.h> 69 70 #define RTE_LOGTYPE_LSI RTE_LOGTYPE_USER1 71 72 #define NB_MBUF 8192 73 74 #define MAX_PKT_BURST 32 75 #define BURST_TX_DRAIN_US 100 /* TX drain every ~100us */ 76 77 /* 78 * Configurable number of RX/TX ring descriptors 79 */ 80 #define RTE_TEST_RX_DESC_DEFAULT 128 81 #define RTE_TEST_TX_DESC_DEFAULT 512 82 static uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT; 83 static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT; 84 85 /* ethernet addresses of ports */ 86 static struct ether_addr lsi_ports_eth_addr[RTE_MAX_ETHPORTS]; 87 88 /* mask of enabled ports */ 89 static uint32_t lsi_enabled_port_mask = 0; 90 91 static unsigned int lsi_rx_queue_per_lcore = 1; 92 93 /* destination port for L2 forwarding */ 94 static unsigned lsi_dst_ports[RTE_MAX_ETHPORTS] = {0}; 95 96 #define MAX_PKT_BURST 32 97 98 #define MAX_RX_QUEUE_PER_LCORE 16 99 #define MAX_TX_QUEUE_PER_PORT 16 100 struct lcore_queue_conf { 101 unsigned n_rx_port; 102 unsigned rx_port_list[MAX_RX_QUEUE_PER_LCORE]; 103 unsigned tx_queue_id; 104 } __rte_cache_aligned; 105 struct lcore_queue_conf lcore_queue_conf[RTE_MAX_LCORE]; 106 107 struct rte_eth_dev_tx_buffer *tx_buffer[RTE_MAX_ETHPORTS]; 108 109 static const struct rte_eth_conf port_conf = { 110 .rxmode = { 111 .split_hdr_size = 0, 112 .header_split = 0, /**< Header Split disabled */ 113 .hw_ip_checksum = 0, /**< IP checksum offload disabled */ 114 .hw_vlan_filter = 0, /**< VLAN filtering disabled */ 115 .jumbo_frame = 0, /**< Jumbo Frame Support disabled */ 116 .hw_strip_crc = 1, /**< CRC stripped by hardware */ 117 }, 118 .txmode = { 119 .mq_mode = ETH_MQ_TX_NONE, 120 }, 121 .intr_conf = { 122 .lsc = 1, /**< lsc interrupt feature enabled */ 123 }, 124 }; 125 126 struct rte_mempool * lsi_pktmbuf_pool = NULL; 127 128 /* Per-port statistics struct */ 129 struct lsi_port_statistics { 130 uint64_t tx; 131 uint64_t rx; 132 uint64_t dropped; 133 } __rte_cache_aligned; 134 struct lsi_port_statistics port_statistics[RTE_MAX_ETHPORTS]; 135 136 /* A tsc-based timer responsible for triggering statistics printout */ 137 #define TIMER_MILLISECOND 2000000ULL /* around 1ms at 2 Ghz */ 138 #define MAX_TIMER_PERIOD 86400 /* 1 day max */ 139 static int64_t timer_period = 10 * TIMER_MILLISECOND * 1000; /* default period is 10 seconds */ 140 141 /* Print out statistics on packets dropped */ 142 static void 143 print_stats(void) 144 { 145 struct rte_eth_link link; 146 uint64_t total_packets_dropped, total_packets_tx, total_packets_rx; 147 uint16_t portid; 148 149 total_packets_dropped = 0; 150 total_packets_tx = 0; 151 total_packets_rx = 0; 152 153 const char clr[] = { 27, '[', '2', 'J', '\0' }; 154 const char topLeft[] = { 27, '[', '1', ';', '1', 'H','\0' }; 155 156 /* Clear screen and move to top left */ 157 printf("%s%s", clr, topLeft); 158 159 printf("\nPort statistics ===================================="); 160 161 for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) { 162 /* skip ports that are not enabled */ 163 if ((lsi_enabled_port_mask & (1 << portid)) == 0) 164 continue; 165 166 memset(&link, 0, sizeof(link)); 167 rte_eth_link_get_nowait(portid, &link); 168 printf("\nStatistics for port %u ------------------------------" 169 "\nLink status: %25s" 170 "\nLink speed: %26u" 171 "\nLink duplex: %25s" 172 "\nPackets sent: %24"PRIu64 173 "\nPackets received: %20"PRIu64 174 "\nPackets dropped: %21"PRIu64, 175 portid, 176 (link.link_status ? "Link up" : "Link down"), 177 (unsigned)link.link_speed, 178 (link.link_duplex == ETH_LINK_FULL_DUPLEX ? \ 179 "full-duplex" : "half-duplex"), 180 port_statistics[portid].tx, 181 port_statistics[portid].rx, 182 port_statistics[portid].dropped); 183 184 total_packets_dropped += port_statistics[portid].dropped; 185 total_packets_tx += port_statistics[portid].tx; 186 total_packets_rx += port_statistics[portid].rx; 187 } 188 printf("\nAggregate statistics ===============================" 189 "\nTotal packets sent: %18"PRIu64 190 "\nTotal packets received: %14"PRIu64 191 "\nTotal packets dropped: %15"PRIu64, 192 total_packets_tx, 193 total_packets_rx, 194 total_packets_dropped); 195 printf("\n====================================================\n"); 196 } 197 198 static void 199 lsi_simple_forward(struct rte_mbuf *m, unsigned portid) 200 { 201 struct ether_hdr *eth; 202 void *tmp; 203 unsigned dst_port = lsi_dst_ports[portid]; 204 int sent; 205 struct rte_eth_dev_tx_buffer *buffer; 206 207 eth = rte_pktmbuf_mtod(m, struct ether_hdr *); 208 209 /* 02:00:00:00:00:xx */ 210 tmp = ð->d_addr.addr_bytes[0]; 211 *((uint64_t *)tmp) = 0x000000000002 + ((uint64_t)dst_port << 40); 212 213 /* src addr */ 214 ether_addr_copy(&lsi_ports_eth_addr[dst_port], ð->s_addr); 215 216 buffer = tx_buffer[dst_port]; 217 sent = rte_eth_tx_buffer(dst_port, 0, buffer, m); 218 if (sent) 219 port_statistics[dst_port].tx += sent; 220 } 221 222 /* main processing loop */ 223 static void 224 lsi_main_loop(void) 225 { 226 struct rte_mbuf *pkts_burst[MAX_PKT_BURST]; 227 struct rte_mbuf *m; 228 unsigned lcore_id; 229 unsigned sent; 230 uint64_t prev_tsc, diff_tsc, cur_tsc, timer_tsc; 231 unsigned i, j, portid, nb_rx; 232 struct lcore_queue_conf *qconf; 233 const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) / US_PER_S * 234 BURST_TX_DRAIN_US; 235 struct rte_eth_dev_tx_buffer *buffer; 236 237 prev_tsc = 0; 238 timer_tsc = 0; 239 240 lcore_id = rte_lcore_id(); 241 qconf = &lcore_queue_conf[lcore_id]; 242 243 if (qconf->n_rx_port == 0) { 244 RTE_LOG(INFO, LSI, "lcore %u has nothing to do\n", lcore_id); 245 return; 246 } 247 248 RTE_LOG(INFO, LSI, "entering main loop on lcore %u\n", lcore_id); 249 250 for (i = 0; i < qconf->n_rx_port; i++) { 251 252 portid = qconf->rx_port_list[i]; 253 RTE_LOG(INFO, LSI, " -- lcoreid=%u portid=%u\n", lcore_id, 254 portid); 255 } 256 257 while (1) { 258 259 cur_tsc = rte_rdtsc(); 260 261 /* 262 * TX burst queue drain 263 */ 264 diff_tsc = cur_tsc - prev_tsc; 265 if (unlikely(diff_tsc > drain_tsc)) { 266 267 for (i = 0; i < qconf->n_rx_port; i++) { 268 269 portid = lsi_dst_ports[qconf->rx_port_list[i]]; 270 buffer = tx_buffer[portid]; 271 272 sent = rte_eth_tx_buffer_flush(portid, 0, buffer); 273 if (sent) 274 port_statistics[portid].tx += sent; 275 276 } 277 278 /* if timer is enabled */ 279 if (timer_period > 0) { 280 281 /* advance the timer */ 282 timer_tsc += diff_tsc; 283 284 /* if timer has reached its timeout */ 285 if (unlikely(timer_tsc >= (uint64_t) timer_period)) { 286 287 /* do this only on master core */ 288 if (lcore_id == rte_get_master_lcore()) { 289 print_stats(); 290 /* reset the timer */ 291 timer_tsc = 0; 292 } 293 } 294 } 295 296 prev_tsc = cur_tsc; 297 } 298 299 /* 300 * Read packet from RX queues 301 */ 302 for (i = 0; i < qconf->n_rx_port; i++) { 303 304 portid = qconf->rx_port_list[i]; 305 nb_rx = rte_eth_rx_burst((uint8_t) portid, 0, 306 pkts_burst, MAX_PKT_BURST); 307 308 port_statistics[portid].rx += nb_rx; 309 310 for (j = 0; j < nb_rx; j++) { 311 m = pkts_burst[j]; 312 rte_prefetch0(rte_pktmbuf_mtod(m, void *)); 313 lsi_simple_forward(m, portid); 314 } 315 } 316 } 317 } 318 319 static int 320 lsi_launch_one_lcore(__attribute__((unused)) void *dummy) 321 { 322 lsi_main_loop(); 323 return 0; 324 } 325 326 /* display usage */ 327 static void 328 lsi_usage(const char *prgname) 329 { 330 printf("%s [EAL options] -- -p PORTMASK [-q NQ]\n" 331 " -p PORTMASK: hexadecimal bitmask of ports to configure\n" 332 " -q NQ: number of queue (=ports) per lcore (default is 1)\n" 333 " -T PERIOD: statistics will be refreshed each PERIOD seconds (0 to disable, 10 default, 86400 maximum)\n", 334 prgname); 335 } 336 337 static int 338 lsi_parse_portmask(const char *portmask) 339 { 340 char *end = NULL; 341 unsigned long pm; 342 343 /* parse hexadecimal string */ 344 pm = strtoul(portmask, &end, 16); 345 if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0')) 346 return -1; 347 348 if (pm == 0) 349 return -1; 350 351 return pm; 352 } 353 354 static unsigned int 355 lsi_parse_nqueue(const char *q_arg) 356 { 357 char *end = NULL; 358 unsigned long n; 359 360 /* parse hexadecimal string */ 361 n = strtoul(q_arg, &end, 10); 362 if ((q_arg[0] == '\0') || (end == NULL) || (*end != '\0')) 363 return 0; 364 if (n == 0) 365 return 0; 366 if (n >= MAX_RX_QUEUE_PER_LCORE) 367 return 0; 368 369 return n; 370 } 371 372 static int 373 lsi_parse_timer_period(const char *q_arg) 374 { 375 char *end = NULL; 376 int n; 377 378 /* parse number string */ 379 n = strtol(q_arg, &end, 10); 380 if ((q_arg[0] == '\0') || (end == NULL) || (*end != '\0')) 381 return -1; 382 if (n >= MAX_TIMER_PERIOD) 383 return -1; 384 385 return n; 386 } 387 388 /* Parse the argument given in the command line of the application */ 389 static int 390 lsi_parse_args(int argc, char **argv) 391 { 392 int opt, ret; 393 char **argvopt; 394 int option_index; 395 char *prgname = argv[0]; 396 static struct option lgopts[] = { 397 {NULL, 0, 0, 0} 398 }; 399 400 argvopt = argv; 401 402 while ((opt = getopt_long(argc, argvopt, "p:q:T:", 403 lgopts, &option_index)) != EOF) { 404 405 switch (opt) { 406 /* portmask */ 407 case 'p': 408 lsi_enabled_port_mask = lsi_parse_portmask(optarg); 409 if (lsi_enabled_port_mask == 0) { 410 printf("invalid portmask\n"); 411 lsi_usage(prgname); 412 return -1; 413 } 414 break; 415 416 /* nqueue */ 417 case 'q': 418 lsi_rx_queue_per_lcore = lsi_parse_nqueue(optarg); 419 if (lsi_rx_queue_per_lcore == 0) { 420 printf("invalid queue number\n"); 421 lsi_usage(prgname); 422 return -1; 423 } 424 break; 425 426 /* timer period */ 427 case 'T': 428 timer_period = lsi_parse_timer_period(optarg) * 1000 * TIMER_MILLISECOND; 429 if (timer_period < 0) { 430 printf("invalid timer period\n"); 431 lsi_usage(prgname); 432 return -1; 433 } 434 break; 435 436 /* long options */ 437 case 0: 438 lsi_usage(prgname); 439 return -1; 440 441 default: 442 lsi_usage(prgname); 443 return -1; 444 } 445 } 446 447 if (optind >= 0) 448 argv[optind-1] = prgname; 449 450 ret = optind-1; 451 optind = 1; /* reset getopt lib */ 452 return ret; 453 } 454 455 /** 456 * It will be called as the callback for specified port after a LSI interrupt 457 * has been fully handled. This callback needs to be implemented carefully as 458 * it will be called in the interrupt host thread which is different from the 459 * application main thread. 460 * 461 * @param port_id 462 * Port id. 463 * @param type 464 * event type. 465 * @param param 466 * Pointer to(address of) the parameters. 467 * 468 * @return 469 * int. 470 */ 471 static int 472 lsi_event_callback(uint16_t port_id, enum rte_eth_event_type type, void *param, 473 void *ret_param) 474 { 475 struct rte_eth_link link; 476 477 RTE_SET_USED(param); 478 RTE_SET_USED(ret_param); 479 480 printf("\n\nIn registered callback...\n"); 481 printf("Event type: %s\n", type == RTE_ETH_EVENT_INTR_LSC ? "LSC interrupt" : "unknown event"); 482 rte_eth_link_get_nowait(port_id, &link); 483 if (link.link_status) { 484 printf("Port %d Link Up - speed %u Mbps - %s\n\n", 485 port_id, (unsigned)link.link_speed, 486 (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? 487 ("full-duplex") : ("half-duplex")); 488 } else 489 printf("Port %d Link Down\n\n", port_id); 490 491 return 0; 492 } 493 494 /* Check the link status of all ports in up to 9s, and print them finally */ 495 static void 496 check_all_ports_link_status(uint16_t port_num, uint32_t port_mask) 497 { 498 #define CHECK_INTERVAL 100 /* 100ms */ 499 #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */ 500 uint8_t count, all_ports_up, print_flag = 0; 501 uint16_t portid; 502 struct rte_eth_link link; 503 504 printf("\nChecking link status"); 505 fflush(stdout); 506 for (count = 0; count <= MAX_CHECK_TIME; count++) { 507 all_ports_up = 1; 508 for (portid = 0; portid < port_num; portid++) { 509 if ((port_mask & (1 << portid)) == 0) 510 continue; 511 memset(&link, 0, sizeof(link)); 512 rte_eth_link_get_nowait(portid, &link); 513 /* print link status if flag set */ 514 if (print_flag == 1) { 515 if (link.link_status) 516 printf( 517 "Port%d Link Up. Speed %u Mbps - %s\n", 518 portid, link.link_speed, 519 (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? 520 ("full-duplex") : ("half-duplex\n")); 521 else 522 printf("Port %d Link Down\n", portid); 523 continue; 524 } 525 /* clear all_ports_up flag if any link down */ 526 if (link.link_status == ETH_LINK_DOWN) { 527 all_ports_up = 0; 528 break; 529 } 530 } 531 /* after finally printing all link status, get out */ 532 if (print_flag == 1) 533 break; 534 535 if (all_ports_up == 0) { 536 printf("."); 537 fflush(stdout); 538 rte_delay_ms(CHECK_INTERVAL); 539 } 540 541 /* set the print_flag if all ports up or timeout */ 542 if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) { 543 print_flag = 1; 544 printf("done\n"); 545 } 546 } 547 } 548 549 int 550 main(int argc, char **argv) 551 { 552 struct lcore_queue_conf *qconf; 553 struct rte_eth_dev_info dev_info; 554 int ret; 555 uint16_t nb_ports; 556 uint16_t portid, portid_last = 0; 557 unsigned lcore_id, rx_lcore_id; 558 unsigned nb_ports_in_mask = 0; 559 560 /* init EAL */ 561 ret = rte_eal_init(argc, argv); 562 if (ret < 0) 563 rte_exit(EXIT_FAILURE, "rte_eal_init failed"); 564 argc -= ret; 565 argv += ret; 566 567 /* parse application arguments (after the EAL ones) */ 568 ret = lsi_parse_args(argc, argv); 569 if (ret < 0) 570 rte_exit(EXIT_FAILURE, "Invalid arguments"); 571 572 /* create the mbuf pool */ 573 lsi_pktmbuf_pool = 574 rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF, 32, 0, 575 RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); 576 if (lsi_pktmbuf_pool == NULL) 577 rte_panic("Cannot init mbuf pool\n"); 578 579 nb_ports = rte_eth_dev_count(); 580 if (nb_ports == 0) 581 rte_panic("No Ethernet port - bye\n"); 582 583 /* 584 * Each logical core is assigned a dedicated TX queue on each port. 585 */ 586 for (portid = 0; portid < nb_ports; portid++) { 587 /* skip ports that are not enabled */ 588 if ((lsi_enabled_port_mask & (1 << portid)) == 0) 589 continue; 590 591 /* save the destination port id */ 592 if (nb_ports_in_mask % 2) { 593 lsi_dst_ports[portid] = portid_last; 594 lsi_dst_ports[portid_last] = portid; 595 } 596 else 597 portid_last = portid; 598 599 nb_ports_in_mask++; 600 601 rte_eth_dev_info_get(portid, &dev_info); 602 } 603 if (nb_ports_in_mask < 2 || nb_ports_in_mask % 2) 604 rte_exit(EXIT_FAILURE, "Current enabled port number is %u, " 605 "but it should be even and at least 2\n", 606 nb_ports_in_mask); 607 608 rx_lcore_id = 0; 609 qconf = &lcore_queue_conf[rx_lcore_id]; 610 611 /* Initialize the port/queue configuration of each logical core */ 612 for (portid = 0; portid < nb_ports; portid++) { 613 /* skip ports that are not enabled */ 614 if ((lsi_enabled_port_mask & (1 << portid)) == 0) 615 continue; 616 617 /* get the lcore_id for this port */ 618 while (rte_lcore_is_enabled(rx_lcore_id) == 0 || 619 lcore_queue_conf[rx_lcore_id].n_rx_port == 620 lsi_rx_queue_per_lcore) { 621 622 rx_lcore_id++; 623 if (rx_lcore_id >= RTE_MAX_LCORE) 624 rte_exit(EXIT_FAILURE, "Not enough cores\n"); 625 } 626 if (qconf != &lcore_queue_conf[rx_lcore_id]) 627 /* Assigned a new logical core in the loop above. */ 628 qconf = &lcore_queue_conf[rx_lcore_id]; 629 630 qconf->rx_port_list[qconf->n_rx_port] = portid; 631 qconf->n_rx_port++; 632 printf("Lcore %u: RX port %u\n",rx_lcore_id, (unsigned) portid); 633 } 634 635 /* Initialise each port */ 636 for (portid = 0; portid < nb_ports; portid++) { 637 /* skip ports that are not enabled */ 638 if ((lsi_enabled_port_mask & (1 << portid)) == 0) { 639 printf("Skipping disabled port %u\n", (unsigned) portid); 640 continue; 641 } 642 /* init port */ 643 printf("Initializing port %u... ", (unsigned) portid); 644 fflush(stdout); 645 ret = rte_eth_dev_configure(portid, 1, 1, &port_conf); 646 if (ret < 0) 647 rte_exit(EXIT_FAILURE, "Cannot configure device: err=%d, port=%u\n", 648 ret, (unsigned) portid); 649 650 ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd, 651 &nb_txd); 652 if (ret < 0) 653 rte_exit(EXIT_FAILURE, 654 "rte_eth_dev_adjust_nb_rx_tx_desc: err=%d, port=%u\n", 655 ret, (unsigned) portid); 656 657 /* register lsi interrupt callback, need to be after 658 * rte_eth_dev_configure(). if (intr_conf.lsc == 0), no 659 * lsc interrupt will be present, and below callback to 660 * be registered will never be called. 661 */ 662 rte_eth_dev_callback_register(portid, 663 RTE_ETH_EVENT_INTR_LSC, lsi_event_callback, NULL); 664 665 rte_eth_macaddr_get(portid, 666 &lsi_ports_eth_addr[portid]); 667 668 /* init one RX queue */ 669 fflush(stdout); 670 ret = rte_eth_rx_queue_setup(portid, 0, nb_rxd, 671 rte_eth_dev_socket_id(portid), 672 NULL, 673 lsi_pktmbuf_pool); 674 if (ret < 0) 675 rte_exit(EXIT_FAILURE, "rte_eth_rx_queue_setup: err=%d, port=%u\n", 676 ret, (unsigned) portid); 677 678 /* init one TX queue logical core on each port */ 679 fflush(stdout); 680 ret = rte_eth_tx_queue_setup(portid, 0, nb_txd, 681 rte_eth_dev_socket_id(portid), 682 NULL); 683 if (ret < 0) 684 rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup: err=%d,port=%u\n", 685 ret, (unsigned) portid); 686 687 /* Initialize TX buffers */ 688 tx_buffer[portid] = rte_zmalloc_socket("tx_buffer", 689 RTE_ETH_TX_BUFFER_SIZE(MAX_PKT_BURST), 0, 690 rte_eth_dev_socket_id(portid)); 691 if (tx_buffer[portid] == NULL) 692 rte_exit(EXIT_FAILURE, "Cannot allocate buffer for tx on port %u\n", 693 (unsigned) portid); 694 695 rte_eth_tx_buffer_init(tx_buffer[portid], MAX_PKT_BURST); 696 697 ret = rte_eth_tx_buffer_set_err_callback(tx_buffer[portid], 698 rte_eth_tx_buffer_count_callback, 699 &port_statistics[portid].dropped); 700 if (ret < 0) 701 rte_exit(EXIT_FAILURE, "Cannot set error callback for " 702 "tx buffer on port %u\n", (unsigned) portid); 703 704 /* Start device */ 705 ret = rte_eth_dev_start(portid); 706 if (ret < 0) 707 rte_exit(EXIT_FAILURE, "rte_eth_dev_start: err=%d, port=%u\n", 708 ret, (unsigned) portid); 709 printf("done:\n"); 710 711 rte_eth_promiscuous_enable(portid); 712 713 printf("Port %u, MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n\n", 714 (unsigned) portid, 715 lsi_ports_eth_addr[portid].addr_bytes[0], 716 lsi_ports_eth_addr[portid].addr_bytes[1], 717 lsi_ports_eth_addr[portid].addr_bytes[2], 718 lsi_ports_eth_addr[portid].addr_bytes[3], 719 lsi_ports_eth_addr[portid].addr_bytes[4], 720 lsi_ports_eth_addr[portid].addr_bytes[5]); 721 722 /* initialize port stats */ 723 memset(&port_statistics, 0, sizeof(port_statistics)); 724 } 725 726 check_all_ports_link_status(nb_ports, lsi_enabled_port_mask); 727 728 /* launch per-lcore init on every lcore */ 729 rte_eal_mp_remote_launch(lsi_launch_one_lcore, NULL, CALL_MASTER); 730 RTE_LCORE_FOREACH_SLAVE(lcore_id) { 731 if (rte_eal_wait_lcore(lcore_id) < 0) 732 return -1; 733 } 734 735 return 0; 736 } 737