first public release
[dpdk.git] / examples / l2fwd-vf / main.c
1 /*-
2  *   BSD LICENSE
3  * 
4  *   Copyright(c) 2010-2012 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  *  version: DPDK.L.1.2.3-3
34  */
35
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <stdint.h>
40 #include <inttypes.h>
41 #include <sys/types.h>
42 #include <string.h>
43 #include <sys/queue.h>
44 #include <netinet/in.h>
45 #include <setjmp.h>
46 #include <stdarg.h>
47 #include <ctype.h>
48 #include <errno.h>
49 #include <getopt.h>
50
51 #include <rte_common.h>
52 #include <rte_log.h>
53 #include <rte_memory.h>
54 #include <rte_memcpy.h>
55 #include <rte_memzone.h>
56 #include <rte_tailq.h>
57 #include <rte_eal.h>
58 #include <rte_per_lcore.h>
59 #include <rte_launch.h>
60 #include <rte_atomic.h>
61 #include <rte_cycles.h>
62 #include <rte_prefetch.h>
63 #include <rte_lcore.h>
64 #include <rte_per_lcore.h>
65 #include <rte_branch_prediction.h>
66 #include <rte_interrupts.h>
67 #include <rte_pci.h>
68 #include <rte_random.h>
69 #include <rte_debug.h>
70 #include <rte_ether.h>
71 #include <rte_ethdev.h>
72 #include <rte_ring.h>
73 #include <rte_mempool.h>
74 #include <rte_mbuf.h>
75
76 #include "main.h"
77
78 #define RTE_LOGTYPE_L2FWD RTE_LOGTYPE_USER1
79
80 #define L2FWD_MAX_PORTS 32
81
82 #define MBUF_SIZE (2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
83 #define NB_MBUF   8192
84
85 /*
86  * RX and TX Prefetch, Host, and Write-back threshold values should be
87  * carefully set for optimal performance. Consult the network
88  * controller's datasheet and supporting DPDK documentation for guidance
89  * on how these parameters should be set.
90  */
91 #define RX_PTHRESH 8 /**< Default values of RX prefetch threshold reg. */
92 #define RX_HTHRESH 8 /**< Default values of RX host threshold reg. */
93 #define RX_WTHRESH 4 /**< Default values of RX write-back threshold reg. */
94
95 /*
96  * These default values are optimized for use with the Intel(R) 82599 10 GbE
97  * Controller and the DPDK ixgbe PMD. Consider using other values for other
98  * network controllers and/or network drivers.
99  */
100 #define TX_PTHRESH 36 /**< Default values of TX prefetch threshold reg. */
101 #define TX_HTHRESH 0  /**< Default values of TX host threshold reg. */
102 #define TX_WTHRESH 0  /**< Default values of TX write-back threshold reg. */
103
104 #define MAX_PKT_BURST 32
105 #define BURST_TX_DRAIN 200000ULL /* around 100us at 2 Ghz */
106
107 #define SOCKET0 0
108
109 /*
110  * Configurable number of RX/TX ring descriptors
111  */
112 #define RTE_TEST_RX_DESC_DEFAULT 128
113 #define RTE_TEST_TX_DESC_DEFAULT 512
114 static uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT;
115 static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT;
116
117 /* ethernet addresses of ports */
118 static struct ether_addr l2fwd_ports_eth_addr[L2FWD_MAX_PORTS];
119
120 /* mask of enabled ports */
121 static uint32_t l2fwd_enabled_port_mask = 0;
122
123 /* list of enabled ports */
124 static uint32_t l2fwd_dst_ports[L2FWD_MAX_PORTS];
125
126 static unsigned int l2fwd_rx_queue_per_lcore = 1;
127
128 #define MAX_PKT_BURST 32
129 struct mbuf_table {
130         unsigned len;
131         struct rte_mbuf *m_table[MAX_PKT_BURST];
132 };
133
134 #define MAX_RX_QUEUE_PER_LCORE 16
135
136 /* Each VF(port) has one Rx/Tx queue (with queueid: 0) */
137 struct lcore_queue_conf {
138
139         unsigned n_rx_queue;
140         unsigned rx_queue_list[MAX_RX_QUEUE_PER_LCORE];
141         unsigned tx_queue_id;
142         struct mbuf_table tx_mbufs[L2FWD_MAX_PORTS];
143
144 } __rte_cache_aligned;
145 struct lcore_queue_conf lcore_queue_conf[RTE_MAX_LCORE];
146
147 static const struct rte_eth_conf port_conf = {
148         .rxmode = {
149                 .split_hdr_size = 0,
150                 .header_split   = 0, /**< Header Split disabled */
151                 .hw_ip_checksum = 0, /**< IP checksum offload disabled */
152                 .hw_vlan_filter = 0, /**< VLAN filtering disabled */
153                 .jumbo_frame    = 0, /**< Jumbo Frame Support disabled */
154                 .hw_strip_crc   = 1, /**< CRC stripped by hardware */
155         },
156         .txmode = {
157         },
158 };
159
160 static const struct rte_eth_rxconf rx_conf = {
161         .rx_thresh = {
162                 .pthresh = RX_PTHRESH,
163                 .hthresh = RX_HTHRESH,
164                 .wthresh = RX_WTHRESH,
165         },
166 };
167
168 static const struct rte_eth_txconf tx_conf = {
169         .tx_thresh = {
170                 .pthresh = TX_PTHRESH,
171                 .hthresh = TX_HTHRESH,
172                 .wthresh = TX_WTHRESH,
173         },
174         .tx_free_thresh = 0, /* Use PMD default values */
175         .tx_rs_thresh = 0, /* Use PMD default values */
176 };
177
178 struct rte_mempool * l2fwd_pktmbuf_pool = NULL;
179
180 /* Per-port statistics struct */
181 struct l2fwd_port_statistics {
182         uint64_t tx;
183         uint64_t rx;
184         uint64_t dropped;
185 } __rte_cache_aligned;
186 struct l2fwd_port_statistics port_statistics[L2FWD_MAX_PORTS];
187
188 /* A tsc-based timer responsible for triggering statistics printout */
189 #define TIMER_MILLISECOND 2000000ULL /* around 1ms at 2 Ghz */
190 #define MAX_TIMER_PERIOD 86400 /* 1 day max */
191 static int64_t timer_period = 10 * TIMER_MILLISECOND * 1000; /* default period is 10 seconds */
192
193 /* Print out statistics on packets dropped */
194 static void
195 print_stats(void)
196 {
197         uint64_t total_packets_dropped, total_packets_tx, total_packets_rx;
198         unsigned portid;
199
200         total_packets_dropped = 0;
201         total_packets_tx = 0;
202         total_packets_rx = 0;
203
204         const char clr[] = { 27, '[', '2', 'J', '\0' };
205         const char topLeft[] = { 27, '[', '1', ';', '1', 'H','\0' };
206
207                 /* Clear screen and move to top left */
208         printf("%s%s", clr, topLeft);
209
210         printf("\nPort statistics ====================================");
211
212         for (portid = 0; portid < L2FWD_MAX_PORTS; portid++) {
213                 /* skip ports that are not enabled */
214                 if ((l2fwd_enabled_port_mask & (1 << portid)) == 0)
215                         continue;
216
217                 printf("\nStatistics for port %u ------------------------------"
218                            "\nPackets sent: %24"PRIu64
219                            "\nPackets received: %20"PRIu64
220                            "\nPackets dropped: %21"PRIu64,
221                            portid,
222                            port_statistics[portid].tx,
223                            port_statistics[portid].rx,
224                            port_statistics[portid].dropped);
225
226                 total_packets_dropped += port_statistics[portid].dropped;
227                 total_packets_tx += port_statistics[portid].tx;
228                 total_packets_rx += port_statistics[portid].rx;
229         }
230         printf("\nAggregate statistics ==============================="
231                    "\nTotal packets sent: %18"PRIu64
232                    "\nTotal packets received: %14"PRIu64
233                    "\nTotal packets dropped: %15"PRIu64,
234                    total_packets_tx,
235                    total_packets_rx,
236                    total_packets_dropped);
237         printf("\n====================================================\n");
238 }
239
240 /* Send the packet on an output interface */
241 static int
242 l2fwd_send_burst(struct lcore_queue_conf *qconf, unsigned n, uint8_t port)
243 {
244         struct rte_mbuf **m_table;
245         unsigned ret;
246         unsigned queueid;
247
248         queueid = (uint16_t) qconf->tx_queue_id;
249         m_table = (struct rte_mbuf **)qconf->tx_mbufs[port].m_table;
250
251         ret = rte_eth_tx_burst(port, (uint16_t) queueid, m_table, (uint16_t) n);
252
253         port_statistics[port].tx += ret;
254         if (unlikely(ret < n)) {
255                 port_statistics[port].dropped += (n - ret);
256                 do {
257                         rte_pktmbuf_free(m_table[ret]);
258                 } while (++ret < n);
259         }
260
261         return 0;
262 }
263
264 /* Send the packet on an output interface */
265 static int
266 l2fwd_send_packet(struct rte_mbuf *m, uint8_t port)
267 {
268         unsigned lcore_id, len;
269         struct lcore_queue_conf *qconf;
270
271         lcore_id = rte_lcore_id();
272
273         qconf = &lcore_queue_conf[lcore_id];
274         len = qconf->tx_mbufs[port].len;
275         qconf->tx_mbufs[port].m_table[len] = m;
276         len++;
277
278         /* enough pkts to be sent */
279         if (unlikely(len == MAX_PKT_BURST)) {
280                 l2fwd_send_burst(qconf, MAX_PKT_BURST, port);
281                 len = 0;
282         }
283
284         qconf->tx_mbufs[port].len = len;
285         return 0;
286 }
287
288 static void
289 l2fwd_simple_forward(struct rte_mbuf *m, unsigned portid)
290 {
291         struct ether_hdr *eth;
292         void *tmp;
293         unsigned dst_port;
294
295         dst_port = l2fwd_dst_ports[portid];
296         eth = rte_pktmbuf_mtod(m, struct ether_hdr *);
297
298         /* 00:09:c0:00:00:xx */
299         tmp = &eth->d_addr.addr_bytes[0];
300         *((uint64_t *)tmp) = 0x000000c00900 + (dst_port << 24);
301
302         /* src addr */
303         ether_addr_copy(&l2fwd_ports_eth_addr[dst_port], &eth->s_addr);
304
305         l2fwd_send_packet(m, (uint8_t) dst_port);
306 }
307
308 /* main processing loop */
309 static void
310 l2fwd_main_loop(void)
311 {
312         struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
313         struct rte_mbuf *m;
314         unsigned lcore_id;
315         unsigned int nb_ports;
316         uint64_t prev_tsc = 0;
317         uint64_t diff_tsc, cur_tsc, timer_tsc;
318         unsigned i, j, portid, nb_rx;
319         struct lcore_queue_conf *qconf;
320
321         timer_tsc = 0;
322
323         lcore_id = rte_lcore_id();
324         qconf = &lcore_queue_conf[lcore_id];
325
326         nb_ports = rte_eth_dev_count();
327         if (nb_ports > L2FWD_MAX_PORTS)
328                 nb_ports = L2FWD_MAX_PORTS;
329
330         if (qconf->n_rx_queue == 0) {
331                 RTE_LOG(INFO, L2FWD, "lcore %u has nothing to do\n", lcore_id);
332                 while(1);
333         }
334
335         RTE_LOG(INFO, L2FWD, "entering main loop on lcore %u\n", lcore_id);
336
337         for (i = 0; i < qconf->n_rx_queue; i++) {
338
339                 portid = qconf->rx_queue_list[i];
340                 RTE_LOG(INFO, L2FWD, " -- lcoreid=%u portid=%u\n", lcore_id,
341                         portid);
342         }
343
344         while (1) {
345
346                 cur_tsc = rte_rdtsc();
347
348                 /*
349                  * TX burst queue drain
350                  */
351                 diff_tsc = cur_tsc - prev_tsc;
352                 if (unlikely(diff_tsc > BURST_TX_DRAIN)) {
353
354                         for (portid = 0; portid < nb_ports; portid++) {
355                                 if (qconf->tx_mbufs[portid].len == 0)
356                                         continue;
357                                 l2fwd_send_burst(&lcore_queue_conf[lcore_id],
358                                                  qconf->tx_mbufs[portid].len,
359                                                  (uint8_t) portid);
360                                 qconf->tx_mbufs[portid].len = 0;
361                         }
362
363                         /* if timer is enabled */
364                         if (timer_period > 0) {
365
366                                 /* advance the timer */
367                                 timer_tsc += diff_tsc;
368
369                                 /* if timer has reached its timeout */
370                                 if (unlikely(timer_tsc >= (uint64_t) timer_period)) {
371
372                                         /* do this only on master core */
373                                         if (lcore_id == rte_get_master_lcore()) {
374                                                 print_stats();
375                                                 /* reset the timer */
376                                                 timer_tsc = 0;
377                                         }
378                                 }
379                         }
380
381                         prev_tsc = cur_tsc;
382                 }
383                 /*
384                  * Read packet from RX queues
385                  */
386                 for (i = 0; i < qconf->n_rx_queue; i++) {
387
388                         portid = qconf->rx_queue_list[i];
389                         nb_rx = rte_eth_rx_burst((uint8_t) portid, 0,
390                                                  pkts_burst, MAX_PKT_BURST);
391
392                         port_statistics[portid].rx += nb_rx;
393
394                         for (j = 0; j < nb_rx; j++) {
395                                 m = pkts_burst[j];
396                                 rte_prefetch0(rte_pktmbuf_mtod(m, void *));
397                                 l2fwd_simple_forward(m, portid);
398                         }
399                 }
400         }
401 }
402
403 static int
404 l2fwd_launch_one_lcore(__attribute__((unused)) void *dummy)
405 {
406         l2fwd_main_loop();
407         return 0;
408 }
409
410 /* display usage */
411 static void
412 l2fwd_usage(const char *prgname)
413 {
414         printf("%s [EAL options] -- -p PORTMASK [-q NQ]\n"
415                "  -p PORTMASK: hexadecimal bitmask of ports to configure\n"
416                "  -q NQ: number of queue (=ports) per lcore (default is 1)\n"
417                "  -T PERIOD: statistics will be refreshed each PERIOD seconds (0 to disable, 10 default, 86400 maximum)\n",
418                prgname);
419 }
420
421 static int
422 l2fwd_parse_portmask(const char *portmask)
423 {
424         char *end = NULL;
425         unsigned long pm;
426
427         /* parse hexadecimal string */
428         pm = strtoul(portmask, &end, 16);
429         if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
430                 return -1;
431
432         if (pm == 0)
433                 return -1;
434
435         return pm;
436 }
437
438 static unsigned int
439 l2fwd_parse_nqueue(const char *q_arg)
440 {
441         char *end = NULL;
442         unsigned long n;
443
444         /* parse hexadecimal string */
445         n = strtoul(q_arg, &end, 10);
446         if ((q_arg[0] == '\0') || (end == NULL) || (*end != '\0'))
447                 return 0;
448         if (n == 0)
449                 return 0;
450         if (n >= MAX_RX_QUEUE_PER_LCORE)
451                 return 0;
452
453         return n;
454 }
455
456 static int
457 l2fwd_parse_timer_period(const char *q_arg)
458 {
459         char *end = NULL;
460         int n;
461
462         /* parse number string */
463         n = strtol(q_arg, &end, 10);
464         if ((q_arg[0] == '\0') || (end == NULL) || (*end != '\0'))
465                 return -1;
466         if (n >= MAX_TIMER_PERIOD)
467                 return -1;
468
469         return n;
470 }
471
472 /* Parse the argument given in the command line of the application */
473 static int
474 l2fwd_parse_args(int argc, char **argv)
475 {
476         int opt, ret;
477         char **argvopt;
478         int option_index;
479         char *prgname = argv[0];
480         static struct option lgopts[] = {
481                 {NULL, 0, 0, 0}
482         };
483
484         argvopt = argv;
485
486         while ((opt = getopt_long(argc, argvopt, "p:q:T:",
487                                   lgopts, &option_index)) != EOF) {
488
489                 switch (opt) {
490                 /* portmask */
491                 case 'p':
492                         l2fwd_enabled_port_mask = l2fwd_parse_portmask(optarg);
493                         if (l2fwd_enabled_port_mask == 0) {
494                                 printf("invalid portmask\n");
495                                 l2fwd_usage(prgname);
496                                 return -1;
497                         }
498                         break;
499
500                 /* nqueue */
501                 case 'q':
502                         l2fwd_rx_queue_per_lcore = l2fwd_parse_nqueue(optarg);
503                         if (l2fwd_rx_queue_per_lcore == 0) {
504                                 printf("invalid queue number\n");
505                                 l2fwd_usage(prgname);
506                                 return -1;
507                         }
508                         break;
509
510                 /* timer period */
511                 case 'T':
512                         timer_period = l2fwd_parse_timer_period(optarg) * 1000 * TIMER_MILLISECOND;
513                         if (timer_period < 0) {
514                                 printf("invalid timer period\n");
515                                 l2fwd_usage(prgname);
516                                 return -1;
517                         }
518                         break;
519
520                 /* long options */
521                 case 0:
522                         l2fwd_usage(prgname);
523                         return -1;
524
525                 default:
526                         l2fwd_usage(prgname);
527                         return -1;
528                 }
529         }
530
531         if (optind >= 0)
532                 argv[optind-1] = prgname;
533
534         ret = optind-1;
535         optind = 0; /* reset getopt lib */
536         return ret;
537 }
538
539 int
540 MAIN(int argc, char **argv)
541 {
542         struct lcore_queue_conf *qconf;
543         int ret;
544         unsigned int nb_ports;
545         unsigned portid;
546         unsigned lcore_id, rx_lcore_id;
547         unsigned last_port;
548         unsigned nb_ports_in_mask = 0;
549
550         /* init EAL */
551         ret = rte_eal_init(argc, argv);
552         if (ret < 0)
553                 rte_exit(EXIT_FAILURE, "Invalid EAL parameters\n");
554         argc -= ret;
555         argv += ret;
556
557         /* parse application arguments (after the EAL ones) */
558         ret = l2fwd_parse_args(argc, argv);
559         if (ret < 0)
560                 rte_exit(EXIT_FAILURE, "Invalid L2FWD-VF parameters\n");
561
562         /* create the mbuf pool */
563         l2fwd_pktmbuf_pool =
564                 rte_mempool_create("mbuf_pool", NB_MBUF,
565                                    MBUF_SIZE, 32,
566                                    sizeof(struct rte_pktmbuf_pool_private),
567                                    rte_pktmbuf_pool_init, NULL,
568                                    rte_pktmbuf_init, NULL,
569                                    SOCKET0, 0);
570         if (l2fwd_pktmbuf_pool == NULL)
571                 rte_exit(EXIT_FAILURE, "Cannot init mbuf pool\n");
572
573         /* init driver(s) */
574 #ifdef RTE_LIBRTE_IGB_PMD
575         if (rte_igb_pmd_init() < 0)
576                 rte_exit(EXIT_FAILURE, "Cannot init igb pmd\n");
577 #endif
578 #ifdef RTE_LIBRTE_IXGBE_PMD
579         if (rte_ixgbe_pmd_init() < 0)
580                 rte_exit(EXIT_FAILURE, "Cannot init ixgbe pmd\n");
581
582         if (rte_ixgbevf_pmd_init() < 0)
583                 rte_exit(EXIT_FAILURE, "Cannot init ixgbevf pmd\n");
584 #endif
585
586         if (rte_eal_pci_probe() < 0)
587                 rte_exit(EXIT_FAILURE, "Cannot probe PCI\n");
588
589         nb_ports = rte_eth_dev_count();
590         if (nb_ports == 0)
591                 rte_exit(EXIT_FAILURE, "No Ethernet port - bye\n");
592
593         if (nb_ports > L2FWD_MAX_PORTS)
594                 nb_ports = L2FWD_MAX_PORTS;
595
596         /* reset l2fwd_dst_ports */
597         for (portid = 0; portid < L2FWD_MAX_PORTS; portid++)
598                 l2fwd_dst_ports[portid] = 0;
599         last_port = 0;
600
601         rx_lcore_id = 0;
602         qconf = &lcore_queue_conf[rx_lcore_id];
603
604         /*
605          * Initialize the lcore/port-rx-queue configuration of each lcore.
606          * NOTE: Each logical core sends packets out to all port-tx-queues
607          */
608         for (portid = 0; portid < nb_ports; portid++) {
609
610                 /* skip ports that are not enabled */
611                 if ((l2fwd_enabled_port_mask & (1 << portid)) == 0)
612                         continue;
613
614                 if (nb_ports_in_mask % 2) {
615                         l2fwd_dst_ports[portid] = last_port;
616                         l2fwd_dst_ports[last_port] = portid;
617                 }
618                 else
619                         last_port = portid;
620
621                 nb_ports_in_mask++;
622
623                 while (rte_lcore_is_enabled(rx_lcore_id) == 0 ||
624                                        lcore_queue_conf[rx_lcore_id].n_rx_queue ==
625                                        l2fwd_rx_queue_per_lcore) {
626
627                         rx_lcore_id++;
628                         if (rx_lcore_id >= RTE_MAX_LCORE)
629                                 rte_exit(EXIT_FAILURE, "Not enough cores\n");
630                 }
631
632                 qconf = &lcore_queue_conf[rx_lcore_id];
633                 qconf->tx_queue_id = 0;
634                 qconf->rx_queue_list[qconf->n_rx_queue] = portid;
635                 qconf->n_rx_queue++;
636
637                 printf("Lcore %u: RX port %u\n", rx_lcore_id, portid);
638
639         }
640
641         /* Initialise each port */
642         for (portid = 0; portid < nb_ports; portid++) {
643
644                 /* skip ports that are not enabled */
645                 if ((l2fwd_enabled_port_mask & (1 << portid)) == 0) {
646                         printf("Skipping disabled port %u\n", portid);
647                         continue;
648                 }
649
650                 /* init port */
651                 printf("Initializing port %u... ", portid);
652                 fflush(stdout);
653                 ret = rte_eth_dev_configure((uint8_t) portid, 1, 1, &port_conf);
654                 if (ret < 0)
655                         rte_exit(EXIT_FAILURE, "Cannot configure device: err=%d, port=%u\n",
656                                   ret, portid);
657
658                 rte_eth_macaddr_get((uint8_t) portid,
659                                     &l2fwd_ports_eth_addr[portid]);
660
661                 /* init one RX queue */
662                 fflush(stdout);
663                 ret = rte_eth_rx_queue_setup((uint8_t) portid, 0, nb_rxd,
664                                              SOCKET0, &rx_conf,
665                                              l2fwd_pktmbuf_pool);
666                 if (ret < 0)
667                         rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup: err=%d, port=%u\n",
668                                   ret, portid);
669
670                 /* init one TX queue */
671                 fflush(stdout);
672                 ret = rte_eth_tx_queue_setup((uint8_t) portid, 0, nb_txd,
673                                              SOCKET0, &tx_conf);
674                 if (ret < 0)
675                         rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup: err=%d, port=%u\n",
676                                   ret, portid);
677
678                 /* Start device */
679                 ret = rte_eth_dev_start((uint8_t) portid);
680                 if (ret < 0)
681                         rte_exit(EXIT_FAILURE, "rte_eth_dev_start: err=%d, port=%u\n",
682                                   ret, portid);
683
684                 printf("done: ");
685                 fflush(stdout);
686
687                 printf("Port %u, MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n\n",
688                                 portid,
689                                 l2fwd_ports_eth_addr[portid].addr_bytes[0],
690                                 l2fwd_ports_eth_addr[portid].addr_bytes[1],
691                                 l2fwd_ports_eth_addr[portid].addr_bytes[2],
692                                 l2fwd_ports_eth_addr[portid].addr_bytes[3],
693                                 l2fwd_ports_eth_addr[portid].addr_bytes[4],
694                                 l2fwd_ports_eth_addr[portid].addr_bytes[5]);
695
696                 /* initialize port stats */
697                 memset(&port_statistics, 0, sizeof(port_statistics));
698         }
699
700         /* launch per-lcore init on every lcore */
701         rte_eal_mp_remote_launch(l2fwd_launch_one_lcore, NULL, CALL_MASTER);
702         RTE_LCORE_FOREACH_SLAVE(lcore_id) {
703                 if (rte_eal_wait_lcore(lcore_id) < 0)
704                         return -1;
705         }
706
707         return 0;
708 }