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