1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
11 #include <sys/queue.h>
18 #include <rte_common.h>
20 #include <rte_byteorder.h>
22 #include <rte_memory.h>
23 #include <rte_memcpy.h>
25 #include <rte_launch.h>
26 #include <rte_atomic.h>
27 #include <rte_cycles.h>
28 #include <rte_prefetch.h>
29 #include <rte_lcore.h>
30 #include <rte_per_lcore.h>
31 #include <rte_branch_prediction.h>
32 #include <rte_interrupts.h>
33 #include <rte_random.h>
34 #include <rte_debug.h>
35 #include <rte_ether.h>
36 #include <rte_ethdev.h>
37 #include <rte_mempool.h>
42 #include <rte_string_fns.h>
43 #include <rte_cpuflags.h>
45 #include <cmdline_parse.h>
46 #include <cmdline_parse_etheraddr.h>
51 * Configurable number of RX/TX ring descriptors
53 #define RTE_TEST_RX_DESC_DEFAULT 1024
54 #define RTE_TEST_TX_DESC_DEFAULT 1024
56 #define MAX_TX_QUEUE_PER_PORT RTE_MAX_ETHPORTS
57 #define MAX_RX_QUEUE_PER_PORT 128
59 #define MAX_LCORE_PARAMS 1024
61 /* Static global variables used within this file. */
62 static uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT;
63 static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT;
65 /**< Ports set in promiscuous mode off by default. */
66 static int promiscuous_on;
68 /* Select Longest-Prefix or Exact match. */
69 static int l3fwd_lpm_on;
70 static int l3fwd_em_on;
72 /* Global variables. */
74 static int numa_on = 1; /**< NUMA is enabled by default. */
75 static int parse_ptype; /**< Parse packet type using rx callback, and */
76 /**< disabled by default */
77 static int per_port_pool; /**< Use separate buffer pools per port; disabled */
80 volatile bool force_quit;
82 /* ethernet addresses of ports */
83 uint64_t dest_eth_addr[RTE_MAX_ETHPORTS];
84 struct rte_ether_addr ports_eth_addr[RTE_MAX_ETHPORTS];
86 xmm_t val_eth[RTE_MAX_ETHPORTS];
88 /* mask of enabled ports */
89 uint32_t enabled_port_mask;
91 /* Used only in exact match mode. */
92 int ipv6; /**< ipv6 is false by default. */
93 uint32_t hash_entry_number = HASH_ENTRY_NUMBER_DEFAULT;
95 struct lcore_conf lcore_conf[RTE_MAX_LCORE];
101 } __rte_cache_aligned;
103 static struct lcore_params lcore_params_array[MAX_LCORE_PARAMS];
104 static struct lcore_params lcore_params_array_default[] = {
116 static struct lcore_params * lcore_params = lcore_params_array_default;
117 static uint16_t nb_lcore_params = sizeof(lcore_params_array_default) /
118 sizeof(lcore_params_array_default[0]);
120 static struct rte_eth_conf port_conf = {
122 .mq_mode = ETH_MQ_RX_RSS,
123 .max_rx_pkt_len = RTE_ETHER_MAX_LEN,
125 .offloads = DEV_RX_OFFLOAD_CHECKSUM,
130 .rss_hf = ETH_RSS_IP,
134 .mq_mode = ETH_MQ_TX_NONE,
138 static struct rte_mempool *pktmbuf_pool[RTE_MAX_ETHPORTS][NB_SOCKETS];
139 static uint8_t lkp_per_socket[NB_SOCKETS];
141 struct l3fwd_lkp_mode {
143 int (*check_ptype)(int);
144 rte_rx_callback_fn cb_parse_ptype;
145 int (*main_loop)(void *);
146 void* (*get_ipv4_lookup_struct)(int);
147 void* (*get_ipv6_lookup_struct)(int);
150 static struct l3fwd_lkp_mode l3fwd_lkp;
152 static struct l3fwd_lkp_mode l3fwd_em_lkp = {
154 .check_ptype = em_check_ptype,
155 .cb_parse_ptype = em_cb_parse_ptype,
156 .main_loop = em_main_loop,
157 .get_ipv4_lookup_struct = em_get_ipv4_l3fwd_lookup_struct,
158 .get_ipv6_lookup_struct = em_get_ipv6_l3fwd_lookup_struct,
161 static struct l3fwd_lkp_mode l3fwd_lpm_lkp = {
163 .check_ptype = lpm_check_ptype,
164 .cb_parse_ptype = lpm_cb_parse_ptype,
165 .main_loop = lpm_main_loop,
166 .get_ipv4_lookup_struct = lpm_get_ipv4_l3fwd_lookup_struct,
167 .get_ipv6_lookup_struct = lpm_get_ipv6_l3fwd_lookup_struct,
171 * Setup lookup methods for forwarding.
172 * Currently exact-match and longest-prefix-match
173 * are supported ones.
176 setup_l3fwd_lookup_tables(void)
178 /* Setup HASH lookup functions. */
180 l3fwd_lkp = l3fwd_em_lkp;
181 /* Setup LPM lookup functions. */
183 l3fwd_lkp = l3fwd_lpm_lkp;
187 check_lcore_params(void)
189 uint8_t queue, lcore;
193 for (i = 0; i < nb_lcore_params; ++i) {
194 queue = lcore_params[i].queue_id;
195 if (queue >= MAX_RX_QUEUE_PER_PORT) {
196 printf("invalid queue number: %hhu\n", queue);
199 lcore = lcore_params[i].lcore_id;
200 if (!rte_lcore_is_enabled(lcore)) {
201 printf("error: lcore %hhu is not enabled in lcore mask\n", lcore);
204 if ((socketid = rte_lcore_to_socket_id(lcore) != 0) &&
206 printf("warning: lcore %hhu is on socket %d with numa off \n",
214 check_port_config(void)
219 for (i = 0; i < nb_lcore_params; ++i) {
220 portid = lcore_params[i].port_id;
221 if ((enabled_port_mask & (1 << portid)) == 0) {
222 printf("port %u is not enabled in port mask\n", portid);
225 if (!rte_eth_dev_is_valid_port(portid)) {
226 printf("port %u is not present on the board\n", portid);
234 get_port_n_rx_queues(const uint16_t port)
239 for (i = 0; i < nb_lcore_params; ++i) {
240 if (lcore_params[i].port_id == port) {
241 if (lcore_params[i].queue_id == queue+1)
242 queue = lcore_params[i].queue_id;
244 rte_exit(EXIT_FAILURE, "queue ids of the port %d must be"
245 " in sequence and must start with 0\n",
246 lcore_params[i].port_id);
249 return (uint8_t)(++queue);
253 init_lcore_rx_queues(void)
255 uint16_t i, nb_rx_queue;
258 for (i = 0; i < nb_lcore_params; ++i) {
259 lcore = lcore_params[i].lcore_id;
260 nb_rx_queue = lcore_conf[lcore].n_rx_queue;
261 if (nb_rx_queue >= MAX_RX_QUEUE_PER_LCORE) {
262 printf("error: too many queues (%u) for lcore: %u\n",
263 (unsigned)nb_rx_queue + 1, (unsigned)lcore);
266 lcore_conf[lcore].rx_queue_list[nb_rx_queue].port_id =
267 lcore_params[i].port_id;
268 lcore_conf[lcore].rx_queue_list[nb_rx_queue].queue_id =
269 lcore_params[i].queue_id;
270 lcore_conf[lcore].n_rx_queue++;
278 print_usage(const char *prgname)
280 fprintf(stderr, "%s [EAL options] --"
285 " --config (port,queue,lcore)[,(port,queue,lcore)]"
286 " [--eth-dest=X,MM:MM:MM:MM:MM:MM]"
287 " [--enable-jumbo [--max-pkt-len PKTLEN]]"
289 " [--hash-entry-num]"
292 " [--per-port-pool]\n\n"
294 " -p PORTMASK: Hexadecimal bitmask of ports to configure\n"
295 " -P : Enable promiscuous mode\n"
296 " -E : Enable exact match\n"
297 " -L : Enable longest prefix match (default)\n"
298 " --config (port,queue,lcore): Rx queue configuration\n"
299 " --eth-dest=X,MM:MM:MM:MM:MM:MM: Ethernet destination for port X\n"
300 " --enable-jumbo: Enable jumbo frames\n"
301 " --max-pkt-len: Under the premise of enabling jumbo,\n"
302 " maximum packet length in decimal (64-9600)\n"
303 " --no-numa: Disable numa awareness\n"
304 " --hash-entry-num: Specify the hash entry number in hexadecimal to be setup\n"
305 " --ipv6: Set if running ipv6 packets\n"
306 " --parse-ptype: Set to use software to analyze packet type\n"
307 " --per-port-pool: Use separate buffer pool per port\n\n",
312 parse_max_pkt_len(const char *pktlen)
317 /* parse decimal string */
318 len = strtoul(pktlen, &end, 10);
319 if ((pktlen[0] == '\0') || (end == NULL) || (*end != '\0'))
329 parse_portmask(const char *portmask)
334 /* parse hexadecimal string */
335 pm = strtoul(portmask, &end, 16);
336 if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
346 parse_hash_entry_number(const char *hash_entry_num)
349 unsigned long hash_en;
350 /* parse hexadecimal string */
351 hash_en = strtoul(hash_entry_num, &end, 16);
352 if ((hash_entry_num[0] == '\0') || (end == NULL) || (*end != '\0'))
362 parse_config(const char *q_arg)
365 const char *p, *p0 = q_arg;
373 unsigned long int_fld[_NUM_FLD];
374 char *str_fld[_NUM_FLD];
380 while ((p = strchr(p0,'(')) != NULL) {
382 if((p0 = strchr(p,')')) == NULL)
386 if(size >= sizeof(s))
389 snprintf(s, sizeof(s), "%.*s", size, p);
390 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
392 for (i = 0; i < _NUM_FLD; i++){
394 int_fld[i] = strtoul(str_fld[i], &end, 0);
395 if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
398 if (nb_lcore_params >= MAX_LCORE_PARAMS) {
399 printf("exceeded max number of lcore params: %hu\n",
403 lcore_params_array[nb_lcore_params].port_id =
404 (uint8_t)int_fld[FLD_PORT];
405 lcore_params_array[nb_lcore_params].queue_id =
406 (uint8_t)int_fld[FLD_QUEUE];
407 lcore_params_array[nb_lcore_params].lcore_id =
408 (uint8_t)int_fld[FLD_LCORE];
411 lcore_params = lcore_params_array;
416 parse_eth_dest(const char *optarg)
420 uint8_t c, *dest, peer_addr[6];
423 portid = strtoul(optarg, &port_end, 10);
424 if (errno != 0 || port_end == optarg || *port_end++ != ',')
425 rte_exit(EXIT_FAILURE,
426 "Invalid eth-dest: %s", optarg);
427 if (portid >= RTE_MAX_ETHPORTS)
428 rte_exit(EXIT_FAILURE,
429 "eth-dest: port %d >= RTE_MAX_ETHPORTS(%d)\n",
430 portid, RTE_MAX_ETHPORTS);
432 if (cmdline_parse_etheraddr(NULL, port_end,
433 &peer_addr, sizeof(peer_addr)) < 0)
434 rte_exit(EXIT_FAILURE,
435 "Invalid ethernet address: %s\n",
437 dest = (uint8_t *)&dest_eth_addr[portid];
438 for (c = 0; c < 6; c++)
439 dest[c] = peer_addr[c];
440 *(uint64_t *)(val_eth + portid) = dest_eth_addr[portid];
443 #define MAX_JUMBO_PKT_LEN 9600
444 #define MEMPOOL_CACHE_SIZE 256
446 static const char short_options[] =
448 "P" /* promiscuous */
449 "L" /* enable long prefix match */
450 "E" /* enable exact match */
453 #define CMD_LINE_OPT_CONFIG "config"
454 #define CMD_LINE_OPT_ETH_DEST "eth-dest"
455 #define CMD_LINE_OPT_NO_NUMA "no-numa"
456 #define CMD_LINE_OPT_IPV6 "ipv6"
457 #define CMD_LINE_OPT_ENABLE_JUMBO "enable-jumbo"
458 #define CMD_LINE_OPT_HASH_ENTRY_NUM "hash-entry-num"
459 #define CMD_LINE_OPT_PARSE_PTYPE "parse-ptype"
460 #define CMD_LINE_OPT_PER_PORT_POOL "per-port-pool"
462 /* long options mapped to a short option */
464 /* first long only option value must be >= 256, so that we won't
465 * conflict with short options */
466 CMD_LINE_OPT_MIN_NUM = 256,
467 CMD_LINE_OPT_CONFIG_NUM,
468 CMD_LINE_OPT_ETH_DEST_NUM,
469 CMD_LINE_OPT_NO_NUMA_NUM,
470 CMD_LINE_OPT_IPV6_NUM,
471 CMD_LINE_OPT_ENABLE_JUMBO_NUM,
472 CMD_LINE_OPT_HASH_ENTRY_NUM_NUM,
473 CMD_LINE_OPT_PARSE_PTYPE_NUM,
474 CMD_LINE_OPT_PARSE_PER_PORT_POOL,
477 static const struct option lgopts[] = {
478 {CMD_LINE_OPT_CONFIG, 1, 0, CMD_LINE_OPT_CONFIG_NUM},
479 {CMD_LINE_OPT_ETH_DEST, 1, 0, CMD_LINE_OPT_ETH_DEST_NUM},
480 {CMD_LINE_OPT_NO_NUMA, 0, 0, CMD_LINE_OPT_NO_NUMA_NUM},
481 {CMD_LINE_OPT_IPV6, 0, 0, CMD_LINE_OPT_IPV6_NUM},
482 {CMD_LINE_OPT_ENABLE_JUMBO, 0, 0, CMD_LINE_OPT_ENABLE_JUMBO_NUM},
483 {CMD_LINE_OPT_HASH_ENTRY_NUM, 1, 0, CMD_LINE_OPT_HASH_ENTRY_NUM_NUM},
484 {CMD_LINE_OPT_PARSE_PTYPE, 0, 0, CMD_LINE_OPT_PARSE_PTYPE_NUM},
485 {CMD_LINE_OPT_PER_PORT_POOL, 0, 0, CMD_LINE_OPT_PARSE_PER_PORT_POOL},
490 * This expression is used to calculate the number of mbufs needed
491 * depending on user input, taking into account memory for rx and
492 * tx hardware rings, cache per lcore and mtable per port per lcore.
493 * RTE_MAX is used to ensure that NB_MBUF never goes below a minimum
496 #define NB_MBUF(nports) RTE_MAX( \
497 (nports*nb_rx_queue*nb_rxd + \
498 nports*nb_lcores*MAX_PKT_BURST + \
499 nports*n_tx_queue*nb_txd + \
500 nb_lcores*MEMPOOL_CACHE_SIZE), \
503 /* Parse the argument given in the command line of the application */
505 parse_args(int argc, char **argv)
510 char *prgname = argv[0];
514 /* Error or normal output strings. */
515 while ((opt = getopt_long(argc, argvopt, short_options,
516 lgopts, &option_index)) != EOF) {
521 enabled_port_mask = parse_portmask(optarg);
522 if (enabled_port_mask == 0) {
523 fprintf(stderr, "Invalid portmask\n");
524 print_usage(prgname);
542 case CMD_LINE_OPT_CONFIG_NUM:
543 ret = parse_config(optarg);
545 fprintf(stderr, "Invalid config\n");
546 print_usage(prgname);
551 case CMD_LINE_OPT_ETH_DEST_NUM:
552 parse_eth_dest(optarg);
555 case CMD_LINE_OPT_NO_NUMA_NUM:
559 case CMD_LINE_OPT_IPV6_NUM:
563 case CMD_LINE_OPT_ENABLE_JUMBO_NUM: {
564 const struct option lenopts = {
565 "max-pkt-len", required_argument, 0, 0
568 port_conf.rxmode.offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
569 port_conf.txmode.offloads |= DEV_TX_OFFLOAD_MULTI_SEGS;
572 * if no max-pkt-len set, use the default
573 * value RTE_ETHER_MAX_LEN.
575 if (getopt_long(argc, argvopt, "",
576 &lenopts, &option_index) == 0) {
577 ret = parse_max_pkt_len(optarg);
578 if (ret < 64 || ret > MAX_JUMBO_PKT_LEN) {
580 "invalid maximum packet length\n");
581 print_usage(prgname);
584 port_conf.rxmode.max_rx_pkt_len = ret;
589 case CMD_LINE_OPT_HASH_ENTRY_NUM_NUM:
590 ret = parse_hash_entry_number(optarg);
591 if ((ret > 0) && (ret <= L3FWD_HASH_ENTRIES)) {
592 hash_entry_number = ret;
594 fprintf(stderr, "invalid hash entry number\n");
595 print_usage(prgname);
600 case CMD_LINE_OPT_PARSE_PTYPE_NUM:
601 printf("soft parse-ptype is enabled\n");
605 case CMD_LINE_OPT_PARSE_PER_PORT_POOL:
606 printf("per port buffer pool is enabled\n");
611 print_usage(prgname);
616 /* If both LPM and EM are selected, return error. */
617 if (l3fwd_lpm_on && l3fwd_em_on) {
618 fprintf(stderr, "LPM and EM are mutually exclusive, select only one\n");
623 * Nothing is selected, pick longest-prefix match
626 if (!l3fwd_lpm_on && !l3fwd_em_on) {
627 fprintf(stderr, "LPM or EM none selected, default LPM on\n");
632 * ipv6 and hash flags are valid only for
633 * exact macth, reset them to default for
634 * longest-prefix match.
638 hash_entry_number = HASH_ENTRY_NUMBER_DEFAULT;
642 argv[optind-1] = prgname;
645 optind = 1; /* reset getopt lib */
650 print_ethaddr(const char *name, const struct rte_ether_addr *eth_addr)
652 char buf[RTE_ETHER_ADDR_FMT_SIZE];
653 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
654 printf("%s%s", name, buf);
658 init_mem(uint16_t portid, unsigned int nb_mbuf)
660 struct lcore_conf *qconf;
665 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
666 if (rte_lcore_is_enabled(lcore_id) == 0)
670 socketid = rte_lcore_to_socket_id(lcore_id);
674 if (socketid >= NB_SOCKETS) {
675 rte_exit(EXIT_FAILURE,
676 "Socket %d of lcore %u is out of range %d\n",
677 socketid, lcore_id, NB_SOCKETS);
680 if (pktmbuf_pool[portid][socketid] == NULL) {
681 snprintf(s, sizeof(s), "mbuf_pool_%d:%d",
683 pktmbuf_pool[portid][socketid] =
684 rte_pktmbuf_pool_create(s, nb_mbuf,
685 MEMPOOL_CACHE_SIZE, 0,
686 RTE_MBUF_DEFAULT_BUF_SIZE, socketid);
687 if (pktmbuf_pool[portid][socketid] == NULL)
688 rte_exit(EXIT_FAILURE,
689 "Cannot init mbuf pool on socket %d\n",
692 printf("Allocated mbuf pool on socket %d\n",
695 /* Setup either LPM or EM(f.e Hash). But, only once per
698 if (!lkp_per_socket[socketid]) {
699 l3fwd_lkp.setup(socketid);
700 lkp_per_socket[socketid] = 1;
703 qconf = &lcore_conf[lcore_id];
704 qconf->ipv4_lookup_struct =
705 l3fwd_lkp.get_ipv4_lookup_struct(socketid);
706 qconf->ipv6_lookup_struct =
707 l3fwd_lkp.get_ipv6_lookup_struct(socketid);
712 /* Check the link status of all ports in up to 9s, and print them finally */
714 check_all_ports_link_status(uint32_t port_mask)
716 #define CHECK_INTERVAL 100 /* 100ms */
717 #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
719 uint8_t count, all_ports_up, print_flag = 0;
720 struct rte_eth_link link;
723 printf("\nChecking link status");
725 for (count = 0; count <= MAX_CHECK_TIME; count++) {
729 RTE_ETH_FOREACH_DEV(portid) {
732 if ((port_mask & (1 << portid)) == 0)
734 memset(&link, 0, sizeof(link));
735 ret = rte_eth_link_get_nowait(portid, &link);
739 printf("Port %u link get failed: %s\n",
740 portid, rte_strerror(-ret));
743 /* print link status if flag set */
744 if (print_flag == 1) {
745 if (link.link_status)
747 "Port%d Link Up. Speed %u Mbps -%s\n",
748 portid, link.link_speed,
749 (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
750 ("full-duplex") : ("half-duplex\n"));
752 printf("Port %d Link Down\n", portid);
755 /* clear all_ports_up flag if any link down */
756 if (link.link_status == ETH_LINK_DOWN) {
761 /* after finally printing all link status, get out */
765 if (all_ports_up == 0) {
768 rte_delay_ms(CHECK_INTERVAL);
771 /* set the print_flag if all ports up or timeout */
772 if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {
780 signal_handler(int signum)
782 if (signum == SIGINT || signum == SIGTERM) {
783 printf("\n\nSignal %d received, preparing to exit...\n",
790 prepare_ptype_parser(uint16_t portid, uint16_t queueid)
793 printf("Port %d: softly parse packet type info\n", portid);
794 if (rte_eth_add_rx_callback(portid, queueid,
795 l3fwd_lkp.cb_parse_ptype,
799 printf("Failed to add rx callback: port=%d\n", portid);
803 if (l3fwd_lkp.check_ptype(portid))
806 printf("port %d cannot parse packet type, please add --%s\n",
807 portid, CMD_LINE_OPT_PARSE_PTYPE);
812 main(int argc, char **argv)
814 struct lcore_conf *qconf;
815 struct rte_eth_dev_info dev_info;
816 struct rte_eth_txconf *txconf;
819 uint16_t queueid, portid;
821 uint32_t n_tx_queue, nb_lcores;
822 uint8_t nb_rx_queue, queue, socketid;
825 ret = rte_eal_init(argc, argv);
827 rte_exit(EXIT_FAILURE, "Invalid EAL parameters\n");
832 signal(SIGINT, signal_handler);
833 signal(SIGTERM, signal_handler);
835 /* pre-init dst MACs for all ports to 02:00:00:00:00:xx */
836 for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) {
837 dest_eth_addr[portid] =
838 RTE_ETHER_LOCAL_ADMIN_ADDR + ((uint64_t)portid << 40);
839 *(uint64_t *)(val_eth + portid) = dest_eth_addr[portid];
842 /* parse application arguments (after the EAL ones) */
843 ret = parse_args(argc, argv);
845 rte_exit(EXIT_FAILURE, "Invalid L3FWD parameters\n");
847 if (check_lcore_params() < 0)
848 rte_exit(EXIT_FAILURE, "check_lcore_params failed\n");
850 ret = init_lcore_rx_queues();
852 rte_exit(EXIT_FAILURE, "init_lcore_rx_queues failed\n");
854 nb_ports = rte_eth_dev_count_avail();
856 if (check_port_config() < 0)
857 rte_exit(EXIT_FAILURE, "check_port_config failed\n");
859 nb_lcores = rte_lcore_count();
861 /* Setup function pointers for lookup method. */
862 setup_l3fwd_lookup_tables();
864 /* initialize all ports */
865 RTE_ETH_FOREACH_DEV(portid) {
866 struct rte_eth_conf local_port_conf = port_conf;
868 /* skip ports that are not enabled */
869 if ((enabled_port_mask & (1 << portid)) == 0) {
870 printf("\nSkipping disabled port %d\n", portid);
875 printf("Initializing port %d ... ", portid );
878 nb_rx_queue = get_port_n_rx_queues(portid);
879 n_tx_queue = nb_lcores;
880 if (n_tx_queue > MAX_TX_QUEUE_PER_PORT)
881 n_tx_queue = MAX_TX_QUEUE_PER_PORT;
882 printf("Creating queues: nb_rxq=%d nb_txq=%u... ",
883 nb_rx_queue, (unsigned)n_tx_queue );
885 ret = rte_eth_dev_info_get(portid, &dev_info);
887 rte_exit(EXIT_FAILURE,
888 "Error during getting device (port %u) info: %s\n",
889 portid, strerror(-ret));
891 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
892 local_port_conf.txmode.offloads |=
893 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
895 local_port_conf.rx_adv_conf.rss_conf.rss_hf &=
896 dev_info.flow_type_rss_offloads;
897 if (local_port_conf.rx_adv_conf.rss_conf.rss_hf !=
898 port_conf.rx_adv_conf.rss_conf.rss_hf) {
899 printf("Port %u modified RSS hash function based on hardware support,"
900 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
902 port_conf.rx_adv_conf.rss_conf.rss_hf,
903 local_port_conf.rx_adv_conf.rss_conf.rss_hf);
906 ret = rte_eth_dev_configure(portid, nb_rx_queue,
907 (uint16_t)n_tx_queue, &local_port_conf);
909 rte_exit(EXIT_FAILURE,
910 "Cannot configure device: err=%d, port=%d\n",
913 ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd,
916 rte_exit(EXIT_FAILURE,
917 "Cannot adjust number of descriptors: err=%d, "
918 "port=%d\n", ret, portid);
920 ret = rte_eth_macaddr_get(portid, &ports_eth_addr[portid]);
922 rte_exit(EXIT_FAILURE,
923 "Cannot get MAC address: err=%d, port=%d\n",
926 print_ethaddr(" Address:", &ports_eth_addr[portid]);
928 print_ethaddr("Destination:",
929 (const struct rte_ether_addr *)&dest_eth_addr[portid]);
933 * prepare src MACs for each port.
935 rte_ether_addr_copy(&ports_eth_addr[portid],
936 (struct rte_ether_addr *)(val_eth + portid) + 1);
939 if (!per_port_pool) {
940 /* portid = 0; this is *not* signifying the first port,
941 * rather, it signifies that portid is ignored.
943 ret = init_mem(0, NB_MBUF(nb_ports));
945 ret = init_mem(portid, NB_MBUF(1));
948 rte_exit(EXIT_FAILURE, "init_mem failed\n");
950 /* init one TX queue per couple (lcore,port) */
952 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
953 if (rte_lcore_is_enabled(lcore_id) == 0)
958 (uint8_t)rte_lcore_to_socket_id(lcore_id);
962 printf("txq=%u,%d,%d ", lcore_id, queueid, socketid);
965 txconf = &dev_info.default_txconf;
966 txconf->offloads = local_port_conf.txmode.offloads;
967 ret = rte_eth_tx_queue_setup(portid, queueid, nb_txd,
970 rte_exit(EXIT_FAILURE,
971 "rte_eth_tx_queue_setup: err=%d, "
972 "port=%d\n", ret, portid);
974 qconf = &lcore_conf[lcore_id];
975 qconf->tx_queue_id[portid] = queueid;
978 qconf->tx_port_id[qconf->n_tx_port] = portid;
984 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
985 if (rte_lcore_is_enabled(lcore_id) == 0)
987 qconf = &lcore_conf[lcore_id];
988 printf("\nInitializing rx queues on lcore %u ... ", lcore_id );
991 for(queue = 0; queue < qconf->n_rx_queue; ++queue) {
992 struct rte_eth_rxconf rxq_conf;
994 portid = qconf->rx_queue_list[queue].port_id;
995 queueid = qconf->rx_queue_list[queue].queue_id;
999 (uint8_t)rte_lcore_to_socket_id(lcore_id);
1003 printf("rxq=%d,%d,%d ", portid, queueid, socketid);
1006 ret = rte_eth_dev_info_get(portid, &dev_info);
1008 rte_exit(EXIT_FAILURE,
1009 "Error during getting device (port %u) info: %s\n",
1010 portid, strerror(-ret));
1012 rxq_conf = dev_info.default_rxconf;
1013 rxq_conf.offloads = port_conf.rxmode.offloads;
1015 ret = rte_eth_rx_queue_setup(portid, queueid,
1018 pktmbuf_pool[0][socketid]);
1020 ret = rte_eth_rx_queue_setup(portid, queueid,
1023 pktmbuf_pool[portid][socketid]);
1025 rte_exit(EXIT_FAILURE,
1026 "rte_eth_rx_queue_setup: err=%d, port=%d\n",
1034 RTE_ETH_FOREACH_DEV(portid) {
1035 if ((enabled_port_mask & (1 << portid)) == 0) {
1039 ret = rte_eth_dev_start(portid);
1041 rte_exit(EXIT_FAILURE,
1042 "rte_eth_dev_start: err=%d, port=%d\n",
1046 * If enabled, put device in promiscuous mode.
1047 * This allows IO forwarding mode to forward packets
1048 * to itself through 2 cross-connected ports of the
1051 if (promiscuous_on) {
1052 ret = rte_eth_promiscuous_enable(portid);
1054 rte_exit(EXIT_FAILURE,
1055 "rte_eth_promiscuous_enable: err=%s, port=%u\n",
1056 rte_strerror(-ret), portid);
1062 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1063 if (rte_lcore_is_enabled(lcore_id) == 0)
1065 qconf = &lcore_conf[lcore_id];
1066 for (queue = 0; queue < qconf->n_rx_queue; ++queue) {
1067 portid = qconf->rx_queue_list[queue].port_id;
1068 queueid = qconf->rx_queue_list[queue].queue_id;
1069 if (prepare_ptype_parser(portid, queueid) == 0)
1070 rte_exit(EXIT_FAILURE, "ptype check fails\n");
1075 check_all_ports_link_status(enabled_port_mask);
1078 /* launch per-lcore init on every lcore */
1079 rte_eal_mp_remote_launch(l3fwd_lkp.main_loop, NULL, CALL_MASTER);
1080 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
1081 if (rte_eal_wait_lcore(lcore_id) < 0) {
1088 RTE_ETH_FOREACH_DEV(portid) {
1089 if ((enabled_port_mask & (1 << portid)) == 0)
1091 printf("Closing port %d...", portid);
1092 rte_eth_dev_stop(portid);
1093 rte_eth_dev_close(portid);