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