1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2016 Intel Corporation 3 */ 4 5 #include <stdio.h> 6 #include <stdlib.h> 7 #include <stdint.h> 8 #include <inttypes.h> 9 #include <sys/types.h> 10 #include <string.h> 11 #include <sys/queue.h> 12 #include <stdarg.h> 13 #include <errno.h> 14 #include <getopt.h> 15 #include <signal.h> 16 #include <stdbool.h> 17 18 #include <rte_common.h> 19 #include <rte_vect.h> 20 #include <rte_byteorder.h> 21 #include <rte_log.h> 22 #include <rte_malloc.h> 23 #include <rte_memory.h> 24 #include <rte_memcpy.h> 25 #include <rte_eal.h> 26 #include <rte_launch.h> 27 #include <rte_atomic.h> 28 #include <rte_cycles.h> 29 #include <rte_prefetch.h> 30 #include <rte_lcore.h> 31 #include <rte_per_lcore.h> 32 #include <rte_branch_prediction.h> 33 #include <rte_interrupts.h> 34 #include <rte_random.h> 35 #include <rte_debug.h> 36 #include <rte_ether.h> 37 #include <rte_mempool.h> 38 #include <rte_mbuf.h> 39 #include <rte_ip.h> 40 #include <rte_tcp.h> 41 #include <rte_udp.h> 42 #include <rte_string_fns.h> 43 #include <rte_cpuflags.h> 44 45 #include <cmdline_parse.h> 46 #include <cmdline_parse_etheraddr.h> 47 48 #include "l3fwd.h" 49 #include "l3fwd_event.h" 50 51 #define MAX_TX_QUEUE_PER_PORT RTE_MAX_ETHPORTS 52 #define MAX_RX_QUEUE_PER_PORT 128 53 54 #define MAX_LCORE_PARAMS 1024 55 56 /* Static global variables used within this file. */ 57 static uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT; 58 static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT; 59 60 /**< Ports set in promiscuous mode off by default. */ 61 static int promiscuous_on; 62 63 /* Select Longest-Prefix or Exact match. */ 64 static int l3fwd_lpm_on; 65 static int l3fwd_em_on; 66 67 /* Global variables. */ 68 69 static int numa_on = 1; /**< NUMA is enabled by default. */ 70 static int parse_ptype; /**< Parse packet type using rx callback, and */ 71 /**< disabled by default */ 72 static int per_port_pool; /**< Use separate buffer pools per port; disabled */ 73 /**< by default */ 74 75 volatile bool force_quit; 76 77 /* ethernet addresses of ports */ 78 uint64_t dest_eth_addr[RTE_MAX_ETHPORTS]; 79 struct rte_ether_addr ports_eth_addr[RTE_MAX_ETHPORTS]; 80 81 xmm_t val_eth[RTE_MAX_ETHPORTS]; 82 83 /* mask of enabled ports */ 84 uint32_t enabled_port_mask; 85 86 /* Used only in exact match mode. */ 87 int ipv6; /**< ipv6 is false by default. */ 88 uint32_t hash_entry_number = HASH_ENTRY_NUMBER_DEFAULT; 89 90 struct lcore_conf lcore_conf[RTE_MAX_LCORE]; 91 92 struct lcore_params { 93 uint16_t port_id; 94 uint8_t queue_id; 95 uint8_t lcore_id; 96 } __rte_cache_aligned; 97 98 static struct lcore_params lcore_params_array[MAX_LCORE_PARAMS]; 99 static struct lcore_params lcore_params_array_default[] = { 100 {0, 0, 2}, 101 {0, 1, 2}, 102 {0, 2, 2}, 103 {1, 0, 2}, 104 {1, 1, 2}, 105 {1, 2, 2}, 106 {2, 0, 2}, 107 {3, 0, 3}, 108 {3, 1, 3}, 109 }; 110 111 static struct lcore_params * lcore_params = lcore_params_array_default; 112 static uint16_t nb_lcore_params = sizeof(lcore_params_array_default) / 113 sizeof(lcore_params_array_default[0]); 114 115 static struct rte_eth_conf port_conf = { 116 .rxmode = { 117 .mq_mode = ETH_MQ_RX_RSS, 118 .max_rx_pkt_len = RTE_ETHER_MAX_LEN, 119 .split_hdr_size = 0, 120 .offloads = DEV_RX_OFFLOAD_CHECKSUM, 121 }, 122 .rx_adv_conf = { 123 .rss_conf = { 124 .rss_key = NULL, 125 .rss_hf = ETH_RSS_IP, 126 }, 127 }, 128 .txmode = { 129 .mq_mode = ETH_MQ_TX_NONE, 130 }, 131 }; 132 133 static struct rte_mempool *pktmbuf_pool[RTE_MAX_ETHPORTS][NB_SOCKETS]; 134 static uint8_t lkp_per_socket[NB_SOCKETS]; 135 136 struct l3fwd_lkp_mode { 137 void (*setup)(int); 138 int (*check_ptype)(int); 139 rte_rx_callback_fn cb_parse_ptype; 140 int (*main_loop)(void *); 141 void* (*get_ipv4_lookup_struct)(int); 142 void* (*get_ipv6_lookup_struct)(int); 143 }; 144 145 static struct l3fwd_lkp_mode l3fwd_lkp; 146 147 static struct l3fwd_lkp_mode l3fwd_em_lkp = { 148 .setup = setup_hash, 149 .check_ptype = em_check_ptype, 150 .cb_parse_ptype = em_cb_parse_ptype, 151 .main_loop = em_main_loop, 152 .get_ipv4_lookup_struct = em_get_ipv4_l3fwd_lookup_struct, 153 .get_ipv6_lookup_struct = em_get_ipv6_l3fwd_lookup_struct, 154 }; 155 156 static struct l3fwd_lkp_mode l3fwd_lpm_lkp = { 157 .setup = setup_lpm, 158 .check_ptype = lpm_check_ptype, 159 .cb_parse_ptype = lpm_cb_parse_ptype, 160 .main_loop = lpm_main_loop, 161 .get_ipv4_lookup_struct = lpm_get_ipv4_l3fwd_lookup_struct, 162 .get_ipv6_lookup_struct = lpm_get_ipv6_l3fwd_lookup_struct, 163 }; 164 165 /* 166 * Setup lookup methods for forwarding. 167 * Currently exact-match and longest-prefix-match 168 * are supported ones. 169 */ 170 static void 171 setup_l3fwd_lookup_tables(void) 172 { 173 /* Setup HASH lookup functions. */ 174 if (l3fwd_em_on) 175 l3fwd_lkp = l3fwd_em_lkp; 176 /* Setup LPM lookup functions. */ 177 else 178 l3fwd_lkp = l3fwd_lpm_lkp; 179 } 180 181 static int 182 check_lcore_params(void) 183 { 184 uint8_t queue, lcore; 185 uint16_t i; 186 int socketid; 187 188 for (i = 0; i < nb_lcore_params; ++i) { 189 queue = lcore_params[i].queue_id; 190 if (queue >= MAX_RX_QUEUE_PER_PORT) { 191 printf("invalid queue number: %hhu\n", queue); 192 return -1; 193 } 194 lcore = lcore_params[i].lcore_id; 195 if (!rte_lcore_is_enabled(lcore)) { 196 printf("error: lcore %hhu is not enabled in lcore mask\n", lcore); 197 return -1; 198 } 199 if ((socketid = rte_lcore_to_socket_id(lcore) != 0) && 200 (numa_on == 0)) { 201 printf("warning: lcore %hhu is on socket %d with numa off \n", 202 lcore, socketid); 203 } 204 } 205 return 0; 206 } 207 208 static int 209 check_port_config(void) 210 { 211 uint16_t portid; 212 uint16_t i; 213 214 for (i = 0; i < nb_lcore_params; ++i) { 215 portid = lcore_params[i].port_id; 216 if ((enabled_port_mask & (1 << portid)) == 0) { 217 printf("port %u is not enabled in port mask\n", portid); 218 return -1; 219 } 220 if (!rte_eth_dev_is_valid_port(portid)) { 221 printf("port %u is not present on the board\n", portid); 222 return -1; 223 } 224 } 225 return 0; 226 } 227 228 static uint8_t 229 get_port_n_rx_queues(const uint16_t port) 230 { 231 int queue = -1; 232 uint16_t i; 233 234 for (i = 0; i < nb_lcore_params; ++i) { 235 if (lcore_params[i].port_id == port) { 236 if (lcore_params[i].queue_id == queue+1) 237 queue = lcore_params[i].queue_id; 238 else 239 rte_exit(EXIT_FAILURE, "queue ids of the port %d must be" 240 " in sequence and must start with 0\n", 241 lcore_params[i].port_id); 242 } 243 } 244 return (uint8_t)(++queue); 245 } 246 247 static int 248 init_lcore_rx_queues(void) 249 { 250 uint16_t i, nb_rx_queue; 251 uint8_t lcore; 252 253 for (i = 0; i < nb_lcore_params; ++i) { 254 lcore = lcore_params[i].lcore_id; 255 nb_rx_queue = lcore_conf[lcore].n_rx_queue; 256 if (nb_rx_queue >= MAX_RX_QUEUE_PER_LCORE) { 257 printf("error: too many queues (%u) for lcore: %u\n", 258 (unsigned)nb_rx_queue + 1, (unsigned)lcore); 259 return -1; 260 } else { 261 lcore_conf[lcore].rx_queue_list[nb_rx_queue].port_id = 262 lcore_params[i].port_id; 263 lcore_conf[lcore].rx_queue_list[nb_rx_queue].queue_id = 264 lcore_params[i].queue_id; 265 lcore_conf[lcore].n_rx_queue++; 266 } 267 } 268 return 0; 269 } 270 271 /* display usage */ 272 static void 273 print_usage(const char *prgname) 274 { 275 fprintf(stderr, "%s [EAL options] --" 276 " -p PORTMASK" 277 " [-P]" 278 " [-E]" 279 " [-L]" 280 " --config (port,queue,lcore)[,(port,queue,lcore)]" 281 " [--eth-dest=X,MM:MM:MM:MM:MM:MM]" 282 " [--enable-jumbo [--max-pkt-len PKTLEN]]" 283 " [--no-numa]" 284 " [--hash-entry-num]" 285 " [--ipv6]" 286 " [--parse-ptype]" 287 " [--per-port-pool]" 288 " [--mode]" 289 " [--eventq-sched]\n\n" 290 291 " -p PORTMASK: Hexadecimal bitmask of ports to configure\n" 292 " -P : Enable promiscuous mode\n" 293 " -E : Enable exact match\n" 294 " -L : Enable longest prefix match (default)\n" 295 " --config (port,queue,lcore): Rx queue configuration\n" 296 " --eth-dest=X,MM:MM:MM:MM:MM:MM: Ethernet destination for port X\n" 297 " --enable-jumbo: Enable jumbo frames\n" 298 " --max-pkt-len: Under the premise of enabling jumbo,\n" 299 " maximum packet length in decimal (64-9600)\n" 300 " --no-numa: Disable numa awareness\n" 301 " --hash-entry-num: Specify the hash entry number in hexadecimal to be setup\n" 302 " --ipv6: Set if running ipv6 packets\n" 303 " --parse-ptype: Set to use software to analyze packet type\n" 304 " --per-port-pool: Use separate buffer pool per port\n" 305 " --mode: Packet transfer mode for I/O, poll or eventdev\n" 306 " Default mode = poll\n" 307 " --eventq-sched: Event queue synchronization method\n" 308 " ordered, atomic or parallel.\n" 309 " Default: atomic\n" 310 " Valid only if --mode=eventdev\n" 311 " --event-eth-rxqs: Number of ethernet RX queues per device.\n" 312 " Default: 1\n" 313 " Valid only if --mode=eventdev\n\n", 314 prgname); 315 } 316 317 static int 318 parse_max_pkt_len(const char *pktlen) 319 { 320 char *end = NULL; 321 unsigned long len; 322 323 /* parse decimal string */ 324 len = strtoul(pktlen, &end, 10); 325 if ((pktlen[0] == '\0') || (end == NULL) || (*end != '\0')) 326 return -1; 327 328 if (len == 0) 329 return -1; 330 331 return len; 332 } 333 334 static int 335 parse_portmask(const char *portmask) 336 { 337 char *end = NULL; 338 unsigned long pm; 339 340 /* parse hexadecimal string */ 341 pm = strtoul(portmask, &end, 16); 342 if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0')) 343 return -1; 344 345 if (pm == 0) 346 return -1; 347 348 return pm; 349 } 350 351 static int 352 parse_hash_entry_number(const char *hash_entry_num) 353 { 354 char *end = NULL; 355 unsigned long hash_en; 356 /* parse hexadecimal string */ 357 hash_en = strtoul(hash_entry_num, &end, 16); 358 if ((hash_entry_num[0] == '\0') || (end == NULL) || (*end != '\0')) 359 return -1; 360 361 if (hash_en == 0) 362 return -1; 363 364 return hash_en; 365 } 366 367 static int 368 parse_config(const char *q_arg) 369 { 370 char s[256]; 371 const char *p, *p0 = q_arg; 372 char *end; 373 enum fieldnames { 374 FLD_PORT = 0, 375 FLD_QUEUE, 376 FLD_LCORE, 377 _NUM_FLD 378 }; 379 unsigned long int_fld[_NUM_FLD]; 380 char *str_fld[_NUM_FLD]; 381 int i; 382 unsigned size; 383 384 nb_lcore_params = 0; 385 386 while ((p = strchr(p0,'(')) != NULL) { 387 ++p; 388 if((p0 = strchr(p,')')) == NULL) 389 return -1; 390 391 size = p0 - p; 392 if(size >= sizeof(s)) 393 return -1; 394 395 snprintf(s, sizeof(s), "%.*s", size, p); 396 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD) 397 return -1; 398 for (i = 0; i < _NUM_FLD; i++){ 399 errno = 0; 400 int_fld[i] = strtoul(str_fld[i], &end, 0); 401 if (errno != 0 || end == str_fld[i] || int_fld[i] > 255) 402 return -1; 403 } 404 if (nb_lcore_params >= MAX_LCORE_PARAMS) { 405 printf("exceeded max number of lcore params: %hu\n", 406 nb_lcore_params); 407 return -1; 408 } 409 lcore_params_array[nb_lcore_params].port_id = 410 (uint8_t)int_fld[FLD_PORT]; 411 lcore_params_array[nb_lcore_params].queue_id = 412 (uint8_t)int_fld[FLD_QUEUE]; 413 lcore_params_array[nb_lcore_params].lcore_id = 414 (uint8_t)int_fld[FLD_LCORE]; 415 ++nb_lcore_params; 416 } 417 lcore_params = lcore_params_array; 418 return 0; 419 } 420 421 static void 422 parse_eth_dest(const char *optarg) 423 { 424 uint16_t portid; 425 char *port_end; 426 uint8_t c, *dest, peer_addr[6]; 427 428 errno = 0; 429 portid = strtoul(optarg, &port_end, 10); 430 if (errno != 0 || port_end == optarg || *port_end++ != ',') 431 rte_exit(EXIT_FAILURE, 432 "Invalid eth-dest: %s", optarg); 433 if (portid >= RTE_MAX_ETHPORTS) 434 rte_exit(EXIT_FAILURE, 435 "eth-dest: port %d >= RTE_MAX_ETHPORTS(%d)\n", 436 portid, RTE_MAX_ETHPORTS); 437 438 if (cmdline_parse_etheraddr(NULL, port_end, 439 &peer_addr, sizeof(peer_addr)) < 0) 440 rte_exit(EXIT_FAILURE, 441 "Invalid ethernet address: %s\n", 442 port_end); 443 dest = (uint8_t *)&dest_eth_addr[portid]; 444 for (c = 0; c < 6; c++) 445 dest[c] = peer_addr[c]; 446 *(uint64_t *)(val_eth + portid) = dest_eth_addr[portid]; 447 } 448 449 static void 450 parse_mode(const char *optarg) 451 { 452 struct l3fwd_event_resources *evt_rsrc = l3fwd_get_eventdev_rsrc(); 453 454 if (!strcmp(optarg, "poll")) 455 evt_rsrc->enabled = false; 456 else if (!strcmp(optarg, "eventdev")) 457 evt_rsrc->enabled = true; 458 } 459 460 static void 461 parse_eventq_sched(const char *optarg) 462 { 463 struct l3fwd_event_resources *evt_rsrc = l3fwd_get_eventdev_rsrc(); 464 465 if (!strcmp(optarg, "ordered")) 466 evt_rsrc->sched_type = RTE_SCHED_TYPE_ORDERED; 467 if (!strcmp(optarg, "atomic")) 468 evt_rsrc->sched_type = RTE_SCHED_TYPE_ATOMIC; 469 if (!strcmp(optarg, "parallel")) 470 evt_rsrc->sched_type = RTE_SCHED_TYPE_PARALLEL; 471 } 472 473 static void 474 parse_event_eth_rx_queues(const char *eth_rx_queues) 475 { 476 struct l3fwd_event_resources *evt_rsrc = l3fwd_get_eventdev_rsrc(); 477 char *end = NULL; 478 uint8_t num_eth_rx_queues; 479 480 /* parse decimal string */ 481 num_eth_rx_queues = strtoul(eth_rx_queues, &end, 10); 482 if ((eth_rx_queues[0] == '\0') || (end == NULL) || (*end != '\0')) 483 return; 484 485 if (num_eth_rx_queues == 0) 486 return; 487 488 evt_rsrc->eth_rx_queues = num_eth_rx_queues; 489 } 490 491 #define MAX_JUMBO_PKT_LEN 9600 492 493 static const char short_options[] = 494 "p:" /* portmask */ 495 "P" /* promiscuous */ 496 "L" /* enable long prefix match */ 497 "E" /* enable exact match */ 498 ; 499 500 #define CMD_LINE_OPT_CONFIG "config" 501 #define CMD_LINE_OPT_ETH_DEST "eth-dest" 502 #define CMD_LINE_OPT_NO_NUMA "no-numa" 503 #define CMD_LINE_OPT_IPV6 "ipv6" 504 #define CMD_LINE_OPT_ENABLE_JUMBO "enable-jumbo" 505 #define CMD_LINE_OPT_HASH_ENTRY_NUM "hash-entry-num" 506 #define CMD_LINE_OPT_PARSE_PTYPE "parse-ptype" 507 #define CMD_LINE_OPT_PER_PORT_POOL "per-port-pool" 508 #define CMD_LINE_OPT_MODE "mode" 509 #define CMD_LINE_OPT_EVENTQ_SYNC "eventq-sched" 510 #define CMD_LINE_OPT_EVENT_ETH_RX_QUEUES "event-eth-rxqs" 511 enum { 512 /* long options mapped to a short option */ 513 514 /* first long only option value must be >= 256, so that we won't 515 * conflict with short options */ 516 CMD_LINE_OPT_MIN_NUM = 256, 517 CMD_LINE_OPT_CONFIG_NUM, 518 CMD_LINE_OPT_ETH_DEST_NUM, 519 CMD_LINE_OPT_NO_NUMA_NUM, 520 CMD_LINE_OPT_IPV6_NUM, 521 CMD_LINE_OPT_ENABLE_JUMBO_NUM, 522 CMD_LINE_OPT_HASH_ENTRY_NUM_NUM, 523 CMD_LINE_OPT_PARSE_PTYPE_NUM, 524 CMD_LINE_OPT_PARSE_PER_PORT_POOL, 525 CMD_LINE_OPT_MODE_NUM, 526 CMD_LINE_OPT_EVENTQ_SYNC_NUM, 527 CMD_LINE_OPT_EVENT_ETH_RX_QUEUES_NUM, 528 }; 529 530 static const struct option lgopts[] = { 531 {CMD_LINE_OPT_CONFIG, 1, 0, CMD_LINE_OPT_CONFIG_NUM}, 532 {CMD_LINE_OPT_ETH_DEST, 1, 0, CMD_LINE_OPT_ETH_DEST_NUM}, 533 {CMD_LINE_OPT_NO_NUMA, 0, 0, CMD_LINE_OPT_NO_NUMA_NUM}, 534 {CMD_LINE_OPT_IPV6, 0, 0, CMD_LINE_OPT_IPV6_NUM}, 535 {CMD_LINE_OPT_ENABLE_JUMBO, 0, 0, CMD_LINE_OPT_ENABLE_JUMBO_NUM}, 536 {CMD_LINE_OPT_HASH_ENTRY_NUM, 1, 0, CMD_LINE_OPT_HASH_ENTRY_NUM_NUM}, 537 {CMD_LINE_OPT_PARSE_PTYPE, 0, 0, CMD_LINE_OPT_PARSE_PTYPE_NUM}, 538 {CMD_LINE_OPT_PER_PORT_POOL, 0, 0, CMD_LINE_OPT_PARSE_PER_PORT_POOL}, 539 {CMD_LINE_OPT_MODE, 1, 0, CMD_LINE_OPT_MODE_NUM}, 540 {CMD_LINE_OPT_EVENTQ_SYNC, 1, 0, CMD_LINE_OPT_EVENTQ_SYNC_NUM}, 541 {CMD_LINE_OPT_EVENT_ETH_RX_QUEUES, 1, 0, 542 CMD_LINE_OPT_EVENT_ETH_RX_QUEUES_NUM}, 543 {NULL, 0, 0, 0} 544 }; 545 546 /* 547 * This expression is used to calculate the number of mbufs needed 548 * depending on user input, taking into account memory for rx and 549 * tx hardware rings, cache per lcore and mtable per port per lcore. 550 * RTE_MAX is used to ensure that NB_MBUF never goes below a minimum 551 * value of 8192 552 */ 553 #define NB_MBUF(nports) RTE_MAX( \ 554 (nports*nb_rx_queue*nb_rxd + \ 555 nports*nb_lcores*MAX_PKT_BURST + \ 556 nports*n_tx_queue*nb_txd + \ 557 nb_lcores*MEMPOOL_CACHE_SIZE), \ 558 (unsigned)8192) 559 560 /* Parse the argument given in the command line of the application */ 561 static int 562 parse_args(int argc, char **argv) 563 { 564 int opt, ret; 565 char **argvopt; 566 int option_index; 567 char *prgname = argv[0]; 568 uint8_t lcore_params = 0; 569 uint8_t eventq_sched = 0; 570 uint8_t eth_rx_q = 0; 571 struct l3fwd_event_resources *evt_rsrc = l3fwd_get_eventdev_rsrc(); 572 573 argvopt = argv; 574 575 /* Error or normal output strings. */ 576 while ((opt = getopt_long(argc, argvopt, short_options, 577 lgopts, &option_index)) != EOF) { 578 579 switch (opt) { 580 /* portmask */ 581 case 'p': 582 enabled_port_mask = parse_portmask(optarg); 583 if (enabled_port_mask == 0) { 584 fprintf(stderr, "Invalid portmask\n"); 585 print_usage(prgname); 586 return -1; 587 } 588 break; 589 590 case 'P': 591 promiscuous_on = 1; 592 break; 593 594 case 'E': 595 l3fwd_em_on = 1; 596 break; 597 598 case 'L': 599 l3fwd_lpm_on = 1; 600 break; 601 602 /* long options */ 603 case CMD_LINE_OPT_CONFIG_NUM: 604 ret = parse_config(optarg); 605 if (ret) { 606 fprintf(stderr, "Invalid config\n"); 607 print_usage(prgname); 608 return -1; 609 } 610 lcore_params = 1; 611 break; 612 613 case CMD_LINE_OPT_ETH_DEST_NUM: 614 parse_eth_dest(optarg); 615 break; 616 617 case CMD_LINE_OPT_NO_NUMA_NUM: 618 numa_on = 0; 619 break; 620 621 case CMD_LINE_OPT_IPV6_NUM: 622 ipv6 = 1; 623 break; 624 625 case CMD_LINE_OPT_ENABLE_JUMBO_NUM: { 626 const struct option lenopts = { 627 "max-pkt-len", required_argument, 0, 0 628 }; 629 630 port_conf.rxmode.offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME; 631 port_conf.txmode.offloads |= DEV_TX_OFFLOAD_MULTI_SEGS; 632 633 /* 634 * if no max-pkt-len set, use the default 635 * value RTE_ETHER_MAX_LEN. 636 */ 637 if (getopt_long(argc, argvopt, "", 638 &lenopts, &option_index) == 0) { 639 ret = parse_max_pkt_len(optarg); 640 if (ret < 64 || ret > MAX_JUMBO_PKT_LEN) { 641 fprintf(stderr, 642 "invalid maximum packet length\n"); 643 print_usage(prgname); 644 return -1; 645 } 646 port_conf.rxmode.max_rx_pkt_len = ret; 647 } 648 break; 649 } 650 651 case CMD_LINE_OPT_HASH_ENTRY_NUM_NUM: 652 ret = parse_hash_entry_number(optarg); 653 if ((ret > 0) && (ret <= L3FWD_HASH_ENTRIES)) { 654 hash_entry_number = ret; 655 } else { 656 fprintf(stderr, "invalid hash entry number\n"); 657 print_usage(prgname); 658 return -1; 659 } 660 break; 661 662 case CMD_LINE_OPT_PARSE_PTYPE_NUM: 663 printf("soft parse-ptype is enabled\n"); 664 parse_ptype = 1; 665 break; 666 667 case CMD_LINE_OPT_PARSE_PER_PORT_POOL: 668 printf("per port buffer pool is enabled\n"); 669 per_port_pool = 1; 670 break; 671 672 case CMD_LINE_OPT_MODE_NUM: 673 parse_mode(optarg); 674 break; 675 676 case CMD_LINE_OPT_EVENTQ_SYNC_NUM: 677 parse_eventq_sched(optarg); 678 eventq_sched = 1; 679 break; 680 681 case CMD_LINE_OPT_EVENT_ETH_RX_QUEUES_NUM: 682 parse_event_eth_rx_queues(optarg); 683 eth_rx_q = 1; 684 break; 685 686 default: 687 print_usage(prgname); 688 return -1; 689 } 690 } 691 692 /* If both LPM and EM are selected, return error. */ 693 if (l3fwd_lpm_on && l3fwd_em_on) { 694 fprintf(stderr, "LPM and EM are mutually exclusive, select only one\n"); 695 return -1; 696 } 697 698 if (evt_rsrc->enabled && lcore_params) { 699 fprintf(stderr, "lcore config is not valid when event mode is selected\n"); 700 return -1; 701 } 702 703 if (!evt_rsrc->enabled && eth_rx_q) { 704 fprintf(stderr, "eth_rx_queues is valid only when event mode is selected\n"); 705 return -1; 706 } 707 708 if (!evt_rsrc->enabled && eventq_sched) { 709 fprintf(stderr, "eventq_sched is valid only when event mode is selected\n"); 710 return -1; 711 } 712 713 /* 714 * Nothing is selected, pick longest-prefix match 715 * as default match. 716 */ 717 if (!l3fwd_lpm_on && !l3fwd_em_on) { 718 fprintf(stderr, "LPM or EM none selected, default LPM on\n"); 719 l3fwd_lpm_on = 1; 720 } 721 722 /* 723 * ipv6 and hash flags are valid only for 724 * exact macth, reset them to default for 725 * longest-prefix match. 726 */ 727 if (l3fwd_lpm_on) { 728 ipv6 = 0; 729 hash_entry_number = HASH_ENTRY_NUMBER_DEFAULT; 730 } 731 732 if (optind >= 0) 733 argv[optind-1] = prgname; 734 735 ret = optind-1; 736 optind = 1; /* reset getopt lib */ 737 return ret; 738 } 739 740 static void 741 print_ethaddr(const char *name, const struct rte_ether_addr *eth_addr) 742 { 743 char buf[RTE_ETHER_ADDR_FMT_SIZE]; 744 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr); 745 printf("%s%s", name, buf); 746 } 747 748 int 749 init_mem(uint16_t portid, unsigned int nb_mbuf) 750 { 751 struct lcore_conf *qconf; 752 int socketid; 753 unsigned lcore_id; 754 char s[64]; 755 756 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { 757 if (rte_lcore_is_enabled(lcore_id) == 0) 758 continue; 759 760 if (numa_on) 761 socketid = rte_lcore_to_socket_id(lcore_id); 762 else 763 socketid = 0; 764 765 if (socketid >= NB_SOCKETS) { 766 rte_exit(EXIT_FAILURE, 767 "Socket %d of lcore %u is out of range %d\n", 768 socketid, lcore_id, NB_SOCKETS); 769 } 770 771 if (pktmbuf_pool[portid][socketid] == NULL) { 772 snprintf(s, sizeof(s), "mbuf_pool_%d:%d", 773 portid, socketid); 774 pktmbuf_pool[portid][socketid] = 775 rte_pktmbuf_pool_create(s, nb_mbuf, 776 MEMPOOL_CACHE_SIZE, 0, 777 RTE_MBUF_DEFAULT_BUF_SIZE, socketid); 778 if (pktmbuf_pool[portid][socketid] == NULL) 779 rte_exit(EXIT_FAILURE, 780 "Cannot init mbuf pool on socket %d\n", 781 socketid); 782 else 783 printf("Allocated mbuf pool on socket %d\n", 784 socketid); 785 786 /* Setup either LPM or EM(f.e Hash). But, only once per 787 * available socket. 788 */ 789 if (!lkp_per_socket[socketid]) { 790 l3fwd_lkp.setup(socketid); 791 lkp_per_socket[socketid] = 1; 792 } 793 } 794 qconf = &lcore_conf[lcore_id]; 795 qconf->ipv4_lookup_struct = 796 l3fwd_lkp.get_ipv4_lookup_struct(socketid); 797 qconf->ipv6_lookup_struct = 798 l3fwd_lkp.get_ipv6_lookup_struct(socketid); 799 } 800 return 0; 801 } 802 803 /* Check the link status of all ports in up to 9s, and print them finally */ 804 static void 805 check_all_ports_link_status(uint32_t port_mask) 806 { 807 #define CHECK_INTERVAL 100 /* 100ms */ 808 #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */ 809 uint16_t portid; 810 uint8_t count, all_ports_up, print_flag = 0; 811 struct rte_eth_link link; 812 int ret; 813 814 printf("\nChecking link status"); 815 fflush(stdout); 816 for (count = 0; count <= MAX_CHECK_TIME; count++) { 817 if (force_quit) 818 return; 819 all_ports_up = 1; 820 RTE_ETH_FOREACH_DEV(portid) { 821 if (force_quit) 822 return; 823 if ((port_mask & (1 << portid)) == 0) 824 continue; 825 memset(&link, 0, sizeof(link)); 826 ret = rte_eth_link_get_nowait(portid, &link); 827 if (ret < 0) { 828 all_ports_up = 0; 829 if (print_flag == 1) 830 printf("Port %u link get failed: %s\n", 831 portid, rte_strerror(-ret)); 832 continue; 833 } 834 /* print link status if flag set */ 835 if (print_flag == 1) { 836 if (link.link_status) 837 printf( 838 "Port%d Link Up. Speed %u Mbps -%s\n", 839 portid, link.link_speed, 840 (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? 841 ("full-duplex") : ("half-duplex\n")); 842 else 843 printf("Port %d Link Down\n", portid); 844 continue; 845 } 846 /* clear all_ports_up flag if any link down */ 847 if (link.link_status == ETH_LINK_DOWN) { 848 all_ports_up = 0; 849 break; 850 } 851 } 852 /* after finally printing all link status, get out */ 853 if (print_flag == 1) 854 break; 855 856 if (all_ports_up == 0) { 857 printf("."); 858 fflush(stdout); 859 rte_delay_ms(CHECK_INTERVAL); 860 } 861 862 /* set the print_flag if all ports up or timeout */ 863 if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) { 864 print_flag = 1; 865 printf("done\n"); 866 } 867 } 868 } 869 870 static void 871 signal_handler(int signum) 872 { 873 if (signum == SIGINT || signum == SIGTERM) { 874 printf("\n\nSignal %d received, preparing to exit...\n", 875 signum); 876 force_quit = true; 877 } 878 } 879 880 static int 881 prepare_ptype_parser(uint16_t portid, uint16_t queueid) 882 { 883 if (parse_ptype) { 884 printf("Port %d: softly parse packet type info\n", portid); 885 if (rte_eth_add_rx_callback(portid, queueid, 886 l3fwd_lkp.cb_parse_ptype, 887 NULL)) 888 return 1; 889 890 printf("Failed to add rx callback: port=%d\n", portid); 891 return 0; 892 } 893 894 if (l3fwd_lkp.check_ptype(portid)) 895 return 1; 896 897 printf("port %d cannot parse packet type, please add --%s\n", 898 portid, CMD_LINE_OPT_PARSE_PTYPE); 899 return 0; 900 } 901 902 static void 903 l3fwd_poll_resource_setup(void) 904 { 905 uint8_t nb_rx_queue, queue, socketid; 906 struct rte_eth_dev_info dev_info; 907 uint32_t n_tx_queue, nb_lcores; 908 struct rte_eth_txconf *txconf; 909 struct lcore_conf *qconf; 910 uint16_t queueid, portid; 911 unsigned int nb_ports; 912 unsigned int lcore_id; 913 int ret; 914 915 if (check_lcore_params() < 0) 916 rte_exit(EXIT_FAILURE, "check_lcore_params failed\n"); 917 918 ret = init_lcore_rx_queues(); 919 if (ret < 0) 920 rte_exit(EXIT_FAILURE, "init_lcore_rx_queues failed\n"); 921 922 nb_ports = rte_eth_dev_count_avail(); 923 924 if (check_port_config() < 0) 925 rte_exit(EXIT_FAILURE, "check_port_config failed\n"); 926 927 nb_lcores = rte_lcore_count(); 928 929 /* initialize all ports */ 930 RTE_ETH_FOREACH_DEV(portid) { 931 struct rte_eth_conf local_port_conf = port_conf; 932 933 /* skip ports that are not enabled */ 934 if ((enabled_port_mask & (1 << portid)) == 0) { 935 printf("\nSkipping disabled port %d\n", portid); 936 continue; 937 } 938 939 /* init port */ 940 printf("Initializing port %d ... ", portid ); 941 fflush(stdout); 942 943 nb_rx_queue = get_port_n_rx_queues(portid); 944 n_tx_queue = nb_lcores; 945 if (n_tx_queue > MAX_TX_QUEUE_PER_PORT) 946 n_tx_queue = MAX_TX_QUEUE_PER_PORT; 947 printf("Creating queues: nb_rxq=%d nb_txq=%u... ", 948 nb_rx_queue, (unsigned)n_tx_queue ); 949 950 ret = rte_eth_dev_info_get(portid, &dev_info); 951 if (ret != 0) 952 rte_exit(EXIT_FAILURE, 953 "Error during getting device (port %u) info: %s\n", 954 portid, strerror(-ret)); 955 956 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE) 957 local_port_conf.txmode.offloads |= 958 DEV_TX_OFFLOAD_MBUF_FAST_FREE; 959 960 local_port_conf.rx_adv_conf.rss_conf.rss_hf &= 961 dev_info.flow_type_rss_offloads; 962 if (local_port_conf.rx_adv_conf.rss_conf.rss_hf != 963 port_conf.rx_adv_conf.rss_conf.rss_hf) { 964 printf("Port %u modified RSS hash function based on hardware support," 965 "requested:%#"PRIx64" configured:%#"PRIx64"\n", 966 portid, 967 port_conf.rx_adv_conf.rss_conf.rss_hf, 968 local_port_conf.rx_adv_conf.rss_conf.rss_hf); 969 } 970 971 ret = rte_eth_dev_configure(portid, nb_rx_queue, 972 (uint16_t)n_tx_queue, &local_port_conf); 973 if (ret < 0) 974 rte_exit(EXIT_FAILURE, 975 "Cannot configure device: err=%d, port=%d\n", 976 ret, portid); 977 978 ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd, 979 &nb_txd); 980 if (ret < 0) 981 rte_exit(EXIT_FAILURE, 982 "Cannot adjust number of descriptors: err=%d, " 983 "port=%d\n", ret, portid); 984 985 ret = rte_eth_macaddr_get(portid, &ports_eth_addr[portid]); 986 if (ret < 0) 987 rte_exit(EXIT_FAILURE, 988 "Cannot get MAC address: err=%d, port=%d\n", 989 ret, portid); 990 991 print_ethaddr(" Address:", &ports_eth_addr[portid]); 992 printf(", "); 993 print_ethaddr("Destination:", 994 (const struct rte_ether_addr *)&dest_eth_addr[portid]); 995 printf(", "); 996 997 /* 998 * prepare src MACs for each port. 999 */ 1000 rte_ether_addr_copy(&ports_eth_addr[portid], 1001 (struct rte_ether_addr *)(val_eth + portid) + 1); 1002 1003 /* init memory */ 1004 if (!per_port_pool) { 1005 /* portid = 0; this is *not* signifying the first port, 1006 * rather, it signifies that portid is ignored. 1007 */ 1008 ret = init_mem(0, NB_MBUF(nb_ports)); 1009 } else { 1010 ret = init_mem(portid, NB_MBUF(1)); 1011 } 1012 if (ret < 0) 1013 rte_exit(EXIT_FAILURE, "init_mem failed\n"); 1014 1015 /* init one TX queue per couple (lcore,port) */ 1016 queueid = 0; 1017 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { 1018 if (rte_lcore_is_enabled(lcore_id) == 0) 1019 continue; 1020 1021 if (numa_on) 1022 socketid = 1023 (uint8_t)rte_lcore_to_socket_id(lcore_id); 1024 else 1025 socketid = 0; 1026 1027 printf("txq=%u,%d,%d ", lcore_id, queueid, socketid); 1028 fflush(stdout); 1029 1030 txconf = &dev_info.default_txconf; 1031 txconf->offloads = local_port_conf.txmode.offloads; 1032 ret = rte_eth_tx_queue_setup(portid, queueid, nb_txd, 1033 socketid, txconf); 1034 if (ret < 0) 1035 rte_exit(EXIT_FAILURE, 1036 "rte_eth_tx_queue_setup: err=%d, " 1037 "port=%d\n", ret, portid); 1038 1039 qconf = &lcore_conf[lcore_id]; 1040 qconf->tx_queue_id[portid] = queueid; 1041 queueid++; 1042 1043 qconf->tx_port_id[qconf->n_tx_port] = portid; 1044 qconf->n_tx_port++; 1045 } 1046 printf("\n"); 1047 } 1048 1049 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { 1050 if (rte_lcore_is_enabled(lcore_id) == 0) 1051 continue; 1052 qconf = &lcore_conf[lcore_id]; 1053 printf("\nInitializing rx queues on lcore %u ... ", lcore_id ); 1054 fflush(stdout); 1055 /* init RX queues */ 1056 for(queue = 0; queue < qconf->n_rx_queue; ++queue) { 1057 struct rte_eth_rxconf rxq_conf; 1058 1059 portid = qconf->rx_queue_list[queue].port_id; 1060 queueid = qconf->rx_queue_list[queue].queue_id; 1061 1062 if (numa_on) 1063 socketid = 1064 (uint8_t)rte_lcore_to_socket_id(lcore_id); 1065 else 1066 socketid = 0; 1067 1068 printf("rxq=%d,%d,%d ", portid, queueid, socketid); 1069 fflush(stdout); 1070 1071 ret = rte_eth_dev_info_get(portid, &dev_info); 1072 if (ret != 0) 1073 rte_exit(EXIT_FAILURE, 1074 "Error during getting device (port %u) info: %s\n", 1075 portid, strerror(-ret)); 1076 1077 rxq_conf = dev_info.default_rxconf; 1078 rxq_conf.offloads = port_conf.rxmode.offloads; 1079 if (!per_port_pool) 1080 ret = rte_eth_rx_queue_setup(portid, queueid, 1081 nb_rxd, socketid, 1082 &rxq_conf, 1083 pktmbuf_pool[0][socketid]); 1084 else 1085 ret = rte_eth_rx_queue_setup(portid, queueid, 1086 nb_rxd, socketid, 1087 &rxq_conf, 1088 pktmbuf_pool[portid][socketid]); 1089 if (ret < 0) 1090 rte_exit(EXIT_FAILURE, 1091 "rte_eth_rx_queue_setup: err=%d, port=%d\n", 1092 ret, portid); 1093 } 1094 } 1095 } 1096 1097 static inline int 1098 l3fwd_service_enable(uint32_t service_id) 1099 { 1100 uint8_t min_service_count = UINT8_MAX; 1101 uint32_t slcore_array[RTE_MAX_LCORE]; 1102 unsigned int slcore = 0; 1103 uint8_t service_count; 1104 int32_t slcore_count; 1105 1106 if (!rte_service_lcore_count()) 1107 return -ENOENT; 1108 1109 slcore_count = rte_service_lcore_list(slcore_array, RTE_MAX_LCORE); 1110 if (slcore_count < 0) 1111 return -ENOENT; 1112 /* Get the core which has least number of services running. */ 1113 while (slcore_count--) { 1114 /* Reset default mapping */ 1115 rte_service_map_lcore_set(service_id, 1116 slcore_array[slcore_count], 0); 1117 service_count = rte_service_lcore_count_services( 1118 slcore_array[slcore_count]); 1119 if (service_count < min_service_count) { 1120 slcore = slcore_array[slcore_count]; 1121 min_service_count = service_count; 1122 } 1123 } 1124 if (rte_service_map_lcore_set(service_id, slcore, 1)) 1125 return -ENOENT; 1126 rte_service_lcore_start(slcore); 1127 1128 return 0; 1129 } 1130 1131 static void 1132 l3fwd_event_service_setup(void) 1133 { 1134 struct l3fwd_event_resources *evt_rsrc = l3fwd_get_eventdev_rsrc(); 1135 struct rte_event_dev_info evdev_info; 1136 uint32_t service_id, caps; 1137 int ret, i; 1138 1139 rte_event_dev_info_get(evt_rsrc->event_d_id, &evdev_info); 1140 if (!(evdev_info.event_dev_cap & RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED)) { 1141 ret = rte_event_dev_service_id_get(evt_rsrc->event_d_id, 1142 &service_id); 1143 if (ret != -ESRCH && ret != 0) 1144 rte_exit(EXIT_FAILURE, 1145 "Error in starting eventdev service\n"); 1146 l3fwd_service_enable(service_id); 1147 } 1148 1149 for (i = 0; i < evt_rsrc->rx_adptr.nb_rx_adptr; i++) { 1150 ret = rte_event_eth_rx_adapter_caps_get(evt_rsrc->event_d_id, 1151 evt_rsrc->rx_adptr.rx_adptr[i], &caps); 1152 if (ret < 0) 1153 rte_exit(EXIT_FAILURE, 1154 "Failed to get Rx adapter[%d] caps\n", 1155 evt_rsrc->rx_adptr.rx_adptr[i]); 1156 ret = rte_event_eth_rx_adapter_service_id_get( 1157 evt_rsrc->event_d_id, 1158 &service_id); 1159 if (ret != -ESRCH && ret != 0) 1160 rte_exit(EXIT_FAILURE, 1161 "Error in starting Rx adapter[%d] service\n", 1162 evt_rsrc->rx_adptr.rx_adptr[i]); 1163 l3fwd_service_enable(service_id); 1164 } 1165 1166 for (i = 0; i < evt_rsrc->tx_adptr.nb_tx_adptr; i++) { 1167 ret = rte_event_eth_tx_adapter_caps_get(evt_rsrc->event_d_id, 1168 evt_rsrc->tx_adptr.tx_adptr[i], &caps); 1169 if (ret < 0) 1170 rte_exit(EXIT_FAILURE, 1171 "Failed to get Rx adapter[%d] caps\n", 1172 evt_rsrc->tx_adptr.tx_adptr[i]); 1173 ret = rte_event_eth_tx_adapter_service_id_get( 1174 evt_rsrc->event_d_id, 1175 &service_id); 1176 if (ret != -ESRCH && ret != 0) 1177 rte_exit(EXIT_FAILURE, 1178 "Error in starting Rx adapter[%d] service\n", 1179 evt_rsrc->tx_adptr.tx_adptr[i]); 1180 l3fwd_service_enable(service_id); 1181 } 1182 } 1183 1184 int 1185 main(int argc, char **argv) 1186 { 1187 struct l3fwd_event_resources *evt_rsrc; 1188 struct lcore_conf *qconf; 1189 uint16_t queueid, portid; 1190 unsigned int lcore_id; 1191 uint8_t queue; 1192 int i, ret; 1193 1194 /* init EAL */ 1195 ret = rte_eal_init(argc, argv); 1196 if (ret < 0) 1197 rte_exit(EXIT_FAILURE, "Invalid EAL parameters\n"); 1198 argc -= ret; 1199 argv += ret; 1200 1201 force_quit = false; 1202 signal(SIGINT, signal_handler); 1203 signal(SIGTERM, signal_handler); 1204 1205 /* pre-init dst MACs for all ports to 02:00:00:00:00:xx */ 1206 for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) { 1207 dest_eth_addr[portid] = 1208 RTE_ETHER_LOCAL_ADMIN_ADDR + ((uint64_t)portid << 40); 1209 *(uint64_t *)(val_eth + portid) = dest_eth_addr[portid]; 1210 } 1211 1212 evt_rsrc = l3fwd_get_eventdev_rsrc(); 1213 /* parse application arguments (after the EAL ones) */ 1214 ret = parse_args(argc, argv); 1215 if (ret < 0) 1216 rte_exit(EXIT_FAILURE, "Invalid L3FWD parameters\n"); 1217 1218 /* Setup function pointers for lookup method. */ 1219 setup_l3fwd_lookup_tables(); 1220 1221 evt_rsrc->per_port_pool = per_port_pool; 1222 evt_rsrc->pkt_pool = pktmbuf_pool; 1223 evt_rsrc->port_mask = enabled_port_mask; 1224 /* Configure eventdev parameters if user has requested */ 1225 if (evt_rsrc->enabled) { 1226 l3fwd_event_resource_setup(&port_conf); 1227 if (l3fwd_em_on) 1228 l3fwd_lkp.main_loop = evt_rsrc->ops.em_event_loop; 1229 else 1230 l3fwd_lkp.main_loop = evt_rsrc->ops.lpm_event_loop; 1231 l3fwd_event_service_setup(); 1232 } else 1233 l3fwd_poll_resource_setup(); 1234 1235 /* start ports */ 1236 RTE_ETH_FOREACH_DEV(portid) { 1237 if ((enabled_port_mask & (1 << portid)) == 0) { 1238 continue; 1239 } 1240 /* Start device */ 1241 ret = rte_eth_dev_start(portid); 1242 if (ret < 0) 1243 rte_exit(EXIT_FAILURE, 1244 "rte_eth_dev_start: err=%d, port=%d\n", 1245 ret, portid); 1246 1247 /* 1248 * If enabled, put device in promiscuous mode. 1249 * This allows IO forwarding mode to forward packets 1250 * to itself through 2 cross-connected ports of the 1251 * target machine. 1252 */ 1253 if (promiscuous_on) { 1254 ret = rte_eth_promiscuous_enable(portid); 1255 if (ret != 0) 1256 rte_exit(EXIT_FAILURE, 1257 "rte_eth_promiscuous_enable: err=%s, port=%u\n", 1258 rte_strerror(-ret), portid); 1259 } 1260 } 1261 1262 printf("\n"); 1263 1264 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { 1265 if (rte_lcore_is_enabled(lcore_id) == 0) 1266 continue; 1267 qconf = &lcore_conf[lcore_id]; 1268 for (queue = 0; queue < qconf->n_rx_queue; ++queue) { 1269 portid = qconf->rx_queue_list[queue].port_id; 1270 queueid = qconf->rx_queue_list[queue].queue_id; 1271 if (prepare_ptype_parser(portid, queueid) == 0) 1272 rte_exit(EXIT_FAILURE, "ptype check fails\n"); 1273 } 1274 } 1275 1276 check_all_ports_link_status(enabled_port_mask); 1277 1278 ret = 0; 1279 /* launch per-lcore init on every lcore */ 1280 rte_eal_mp_remote_launch(l3fwd_lkp.main_loop, NULL, CALL_MASTER); 1281 if (evt_rsrc->enabled) { 1282 for (i = 0; i < evt_rsrc->rx_adptr.nb_rx_adptr; i++) 1283 rte_event_eth_rx_adapter_stop( 1284 evt_rsrc->rx_adptr.rx_adptr[i]); 1285 for (i = 0; i < evt_rsrc->tx_adptr.nb_tx_adptr; i++) 1286 rte_event_eth_tx_adapter_stop( 1287 evt_rsrc->tx_adptr.tx_adptr[i]); 1288 1289 RTE_ETH_FOREACH_DEV(portid) { 1290 if ((enabled_port_mask & (1 << portid)) == 0) 1291 continue; 1292 rte_eth_dev_stop(portid); 1293 } 1294 1295 rte_eal_mp_wait_lcore(); 1296 RTE_ETH_FOREACH_DEV(portid) { 1297 if ((enabled_port_mask & (1 << portid)) == 0) 1298 continue; 1299 rte_eth_dev_close(portid); 1300 } 1301 1302 rte_event_dev_stop(evt_rsrc->event_d_id); 1303 rte_event_dev_close(evt_rsrc->event_d_id); 1304 1305 } else { 1306 rte_eal_mp_wait_lcore(); 1307 1308 RTE_ETH_FOREACH_DEV(portid) { 1309 if ((enabled_port_mask & (1 << portid)) == 0) 1310 continue; 1311 printf("Closing port %d...", portid); 1312 rte_eth_dev_stop(portid); 1313 rte_eth_dev_close(portid); 1314 printf(" Done\n"); 1315 } 1316 } 1317 printf("Bye...\n"); 1318 1319 return ret; 1320 } 1321