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