xref: /dpdk/examples/qos_meter/main.c (revision 8d54b1ec4a8be40975ae6978535bcc1431caad02)
13998e2a0SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
23998e2a0SBruce Richardson  * Copyright(c) 2010-2016 Intel Corporation
3e6541fdeSIntel  */
4e6541fdeSIntel 
5e6541fdeSIntel #include <stdio.h>
6*72b452c5SDmitry Kozlyuk #include <stdlib.h>
7e6541fdeSIntel #include <getopt.h>
8e6541fdeSIntel 
9e6541fdeSIntel #include <rte_common.h>
10e6541fdeSIntel #include <rte_eal.h>
11e2366e74STomasz Kulasek #include <rte_malloc.h>
12e6541fdeSIntel #include <rte_mempool.h>
13e6541fdeSIntel #include <rte_ethdev.h>
14e6541fdeSIntel #include <rte_cycles.h>
15e6541fdeSIntel #include <rte_mbuf.h>
16e6541fdeSIntel #include <rte_meter.h>
17e6541fdeSIntel 
189a212dc0SConor Fogarty /* Traffic metering configuration. 8< */
19e6541fdeSIntel #define APP_MODE_FWD                    0
20e6541fdeSIntel #define APP_MODE_SRTCM_COLOR_BLIND      1
21e6541fdeSIntel #define APP_MODE_SRTCM_COLOR_AWARE      2
22e6541fdeSIntel #define APP_MODE_TRTCM_COLOR_BLIND      3
23e6541fdeSIntel #define APP_MODE_TRTCM_COLOR_AWARE      4
24e6541fdeSIntel 
25e6541fdeSIntel #define APP_MODE	APP_MODE_SRTCM_COLOR_BLIND
269a212dc0SConor Fogarty /* >8 End of traffic metering configuration. */
27e6541fdeSIntel 
28e6541fdeSIntel 
29e6541fdeSIntel #include "main.h"
30e6541fdeSIntel 
31e6541fdeSIntel 
32e6541fdeSIntel #define APP_PKT_FLOW_POS                33
33e6541fdeSIntel #define APP_PKT_COLOR_POS               5
34e6541fdeSIntel 
35e6541fdeSIntel 
36e6541fdeSIntel #if APP_PKT_FLOW_POS > 64 || APP_PKT_COLOR_POS > 64
37e6541fdeSIntel #error Byte offset needs to be less than 64
38e6541fdeSIntel #endif
39e6541fdeSIntel 
40e6541fdeSIntel /*
41e6541fdeSIntel  * Buffer pool configuration
42e6541fdeSIntel  *
43e6541fdeSIntel  ***/
44e6541fdeSIntel #define NB_MBUF             8192
45e6541fdeSIntel #define MEMPOOL_CACHE_SIZE  256
46e6541fdeSIntel 
47e6541fdeSIntel static struct rte_mempool *pool = NULL;
48e6541fdeSIntel 
49e6541fdeSIntel /*
50e6541fdeSIntel  * NIC configuration
51e6541fdeSIntel  *
52e6541fdeSIntel  ***/
53e6541fdeSIntel static struct rte_eth_conf port_conf = {
54e6541fdeSIntel 	.rxmode = {
55295968d1SFerruh Yigit 		.mq_mode	= RTE_ETH_MQ_RX_RSS,
56295968d1SFerruh Yigit 		.offloads = RTE_ETH_RX_OFFLOAD_CHECKSUM,
57e6541fdeSIntel 	},
58e6541fdeSIntel 	.rx_adv_conf = {
59e6541fdeSIntel 		.rss_conf = {
60e6541fdeSIntel 			.rss_key = NULL,
61295968d1SFerruh Yigit 			.rss_hf = RTE_ETH_RSS_IP,
62e6541fdeSIntel 		},
63e6541fdeSIntel 	},
64e6541fdeSIntel 	.txmode = {
65295968d1SFerruh Yigit 		.mq_mode = RTE_ETH_MQ_TX_NONE,
66e6541fdeSIntel 	},
67e6541fdeSIntel };
68e6541fdeSIntel 
69867a6c66SKevin Laatz #define NIC_RX_QUEUE_DESC               1024
70867a6c66SKevin Laatz #define NIC_TX_QUEUE_DESC               1024
71e6541fdeSIntel 
72e6541fdeSIntel #define NIC_RX_QUEUE                    0
73e6541fdeSIntel #define NIC_TX_QUEUE                    0
74e6541fdeSIntel 
75e6541fdeSIntel /*
76e6541fdeSIntel  * Packet RX/TX
77e6541fdeSIntel  *
78e6541fdeSIntel  ***/
79daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_BURST_MAX                32
80daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_BURST_MAX                32
81e6541fdeSIntel #define TIME_TX_DRAIN                   200000ULL
82e6541fdeSIntel 
8347523597SZhiyong Yang static uint16_t port_rx;
8447523597SZhiyong Yang static uint16_t port_tx;
85daa02b5cSOlivier Matz static struct rte_mbuf *pkts_rx[RTE_MBUF_F_RX_BURST_MAX];
86e2366e74STomasz Kulasek struct rte_eth_dev_tx_buffer *tx_buffer;
87e6541fdeSIntel 
889a212dc0SConor Fogarty /* Traffic meter parameters are configured in the application. 8< */
89c06ddf96SCristian Dumitrescu struct rte_meter_srtcm_params app_srtcm_params = {
90c06ddf96SCristian Dumitrescu 	.cir = 1000000 * 46,
91c06ddf96SCristian Dumitrescu 	.cbs = 2048,
92c06ddf96SCristian Dumitrescu 	.ebs = 2048
93e6541fdeSIntel };
94e6541fdeSIntel 
95c06ddf96SCristian Dumitrescu struct rte_meter_srtcm_profile app_srtcm_profile;
96c06ddf96SCristian Dumitrescu 
97c06ddf96SCristian Dumitrescu struct rte_meter_trtcm_params app_trtcm_params = {
98c06ddf96SCristian Dumitrescu 	.cir = 1000000 * 46,
99c06ddf96SCristian Dumitrescu 	.pir = 1500000 * 46,
100c06ddf96SCristian Dumitrescu 	.cbs = 2048,
101c06ddf96SCristian Dumitrescu 	.pbs = 2048
102e6541fdeSIntel };
1039a212dc0SConor Fogarty /* >8 End of traffic meter parameters are configured in the application. */
104e6541fdeSIntel 
105c06ddf96SCristian Dumitrescu struct rte_meter_trtcm_profile app_trtcm_profile;
106c06ddf96SCristian Dumitrescu 
107e6541fdeSIntel #define APP_FLOWS_MAX  256
108e6541fdeSIntel 
109e6541fdeSIntel FLOW_METER app_flows[APP_FLOWS_MAX];
110e6541fdeSIntel 
111e752649cSSlawomir Mrozowicz static int
app_configure_flow_table(void)112e6541fdeSIntel app_configure_flow_table(void)
113e6541fdeSIntel {
114c06ddf96SCristian Dumitrescu 	uint32_t i;
115e752649cSSlawomir Mrozowicz 	int ret;
116e6541fdeSIntel 
117c06ddf96SCristian Dumitrescu 	ret = rte_meter_srtcm_profile_config(&app_srtcm_profile,
118c06ddf96SCristian Dumitrescu 		&app_srtcm_params);
119c06ddf96SCristian Dumitrescu 	if (ret)
120c06ddf96SCristian Dumitrescu 		return ret;
121c06ddf96SCristian Dumitrescu 
122c06ddf96SCristian Dumitrescu 	ret = rte_meter_trtcm_profile_config(&app_trtcm_profile,
123c06ddf96SCristian Dumitrescu 		&app_trtcm_params);
124c06ddf96SCristian Dumitrescu 	if (ret)
125c06ddf96SCristian Dumitrescu 		return ret;
126c06ddf96SCristian Dumitrescu 
127c06ddf96SCristian Dumitrescu 	for (i = 0; i < APP_FLOWS_MAX; i++) {
128c06ddf96SCristian Dumitrescu 		ret = FUNC_CONFIG(&app_flows[i], &PROFILE);
129e752649cSSlawomir Mrozowicz 		if (ret)
130e752649cSSlawomir Mrozowicz 			return ret;
131e6541fdeSIntel 	}
132e752649cSSlawomir Mrozowicz 
133e752649cSSlawomir Mrozowicz 	return 0;
134e6541fdeSIntel }
135e6541fdeSIntel 
136e6541fdeSIntel static inline void
app_set_pkt_color(uint8_t * pkt_data,enum policer_action color)137fc8a10d8SIntel app_set_pkt_color(uint8_t *pkt_data, enum policer_action color)
138fc8a10d8SIntel {
139fc8a10d8SIntel 	pkt_data[APP_PKT_COLOR_POS] = (uint8_t)color;
140fc8a10d8SIntel }
141fc8a10d8SIntel 
142fc8a10d8SIntel static inline int
app_pkt_handle(struct rte_mbuf * pkt,uint64_t time)143e6541fdeSIntel app_pkt_handle(struct rte_mbuf *pkt, uint64_t time)
144e6541fdeSIntel {
145fc8a10d8SIntel 	uint8_t input_color, output_color;
146e6541fdeSIntel 	uint8_t *pkt_data = rte_pktmbuf_mtod(pkt, uint8_t *);
1476d13ea8eSOlivier Matz 	uint32_t pkt_len = rte_pktmbuf_pkt_len(pkt) -
1486d13ea8eSOlivier Matz 		sizeof(struct rte_ether_hdr);
149e6541fdeSIntel 	uint8_t flow_id = (uint8_t)(pkt_data[APP_PKT_FLOW_POS] & (APP_FLOWS_MAX - 1));
150fc8a10d8SIntel 	input_color = pkt_data[APP_PKT_COLOR_POS];
151fc8a10d8SIntel 	enum policer_action action;
152e6541fdeSIntel 
153e6541fdeSIntel 	/* color input is not used for blind modes */
154c06ddf96SCristian Dumitrescu 	output_color = (uint8_t) FUNC_METER(&app_flows[flow_id],
155c06ddf96SCristian Dumitrescu 		&PROFILE,
156c06ddf96SCristian Dumitrescu 		time,
157c06ddf96SCristian Dumitrescu 		pkt_len,
158f6feb39cSJasvinder Singh 		(enum rte_color) input_color);
159fc8a10d8SIntel 
160fc8a10d8SIntel 	/* Apply policing and set the output color */
161fc8a10d8SIntel 	action = policer_table[input_color][output_color];
162fc8a10d8SIntel 	app_set_pkt_color(pkt_data, action);
163fc8a10d8SIntel 
164fc8a10d8SIntel 	return action;
165e6541fdeSIntel }
166e6541fdeSIntel 
167e6541fdeSIntel 
168ddcd7640SThomas Monjalon static __rte_noreturn int
main_loop(__rte_unused void * dummy)169f2fc83b4SThomas Monjalon main_loop(__rte_unused void *dummy)
170e6541fdeSIntel {
171e6541fdeSIntel 	uint64_t current_time, last_time = rte_rdtsc();
172e6541fdeSIntel 	uint32_t lcore_id = rte_lcore_id();
173e6541fdeSIntel 
174e6541fdeSIntel 	printf("Core %u: port RX = %d, port TX = %d\n", lcore_id, port_rx, port_tx);
175e6541fdeSIntel 
176e6541fdeSIntel 	while (1) {
177e6541fdeSIntel 		uint64_t time_diff;
178e6541fdeSIntel 		int i, nb_rx;
179e6541fdeSIntel 
180e6541fdeSIntel 		/* Mechanism to avoid stale packets in the output buffer */
181e6541fdeSIntel 		current_time = rte_rdtsc();
182e6541fdeSIntel 		time_diff = current_time - last_time;
183e6541fdeSIntel 		if (unlikely(time_diff > TIME_TX_DRAIN)) {
184e2366e74STomasz Kulasek 			/* Flush tx buffer */
185e2366e74STomasz Kulasek 			rte_eth_tx_buffer_flush(port_tx, NIC_TX_QUEUE, tx_buffer);
186e6541fdeSIntel 			last_time = current_time;
187e6541fdeSIntel 		}
188e6541fdeSIntel 
189e6541fdeSIntel 		/* Read packet burst from NIC RX */
190daa02b5cSOlivier Matz 		nb_rx = rte_eth_rx_burst(port_rx, NIC_RX_QUEUE, pkts_rx, RTE_MBUF_F_RX_BURST_MAX);
191e6541fdeSIntel 
192e6541fdeSIntel 		/* Handle packets */
193e6541fdeSIntel 		for (i = 0; i < nb_rx; i ++) {
194e6541fdeSIntel 			struct rte_mbuf *pkt = pkts_rx[i];
195e6541fdeSIntel 
196e6541fdeSIntel 			/* Handle current packet */
197fc8a10d8SIntel 			if (app_pkt_handle(pkt, current_time) == DROP)
198fc8a10d8SIntel 				rte_pktmbuf_free(pkt);
199e2366e74STomasz Kulasek 			else
200e2366e74STomasz Kulasek 				rte_eth_tx_buffer(port_tx, NIC_TX_QUEUE, tx_buffer, pkt);
201e6541fdeSIntel 		}
202e6541fdeSIntel 	}
203e6541fdeSIntel }
204e6541fdeSIntel 
205e6541fdeSIntel static void
print_usage(const char * prgname)206e6541fdeSIntel print_usage(const char *prgname)
207e6541fdeSIntel {
208e6541fdeSIntel 	printf ("%s [EAL options] -- -p PORTMASK\n"
209e6541fdeSIntel 		"  -p PORTMASK: hexadecimal bitmask of ports to configure\n",
210e6541fdeSIntel 		prgname);
211e6541fdeSIntel }
212e6541fdeSIntel 
213e6541fdeSIntel static int
parse_portmask(const char * portmask)214e6541fdeSIntel parse_portmask(const char *portmask)
215e6541fdeSIntel {
216e6541fdeSIntel 	char *end = NULL;
217e6541fdeSIntel 	unsigned long pm;
218e6541fdeSIntel 
219e6541fdeSIntel 	/* parse hexadecimal string */
220e6541fdeSIntel 	pm = strtoul(portmask, &end, 16);
221e6541fdeSIntel 	if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
222ce6b8c31SSarosh Arif 		return 0;
223e6541fdeSIntel 
224e6541fdeSIntel 	return pm;
225e6541fdeSIntel }
226e6541fdeSIntel 
227e6541fdeSIntel /* Parse the argument given in the command line of the application */
228e6541fdeSIntel static int
parse_args(int argc,char ** argv)229e6541fdeSIntel parse_args(int argc, char **argv)
230e6541fdeSIntel {
231e6541fdeSIntel 	int opt;
232e6541fdeSIntel 	char **argvopt;
233e6541fdeSIntel 	int option_index;
234e6541fdeSIntel 	char *prgname = argv[0];
235e6541fdeSIntel 	static struct option lgopts[] = {
236e6541fdeSIntel 		{NULL, 0, 0, 0}
237e6541fdeSIntel 	};
238e6541fdeSIntel 	uint64_t port_mask, i, mask;
239e6541fdeSIntel 
240e6541fdeSIntel 	argvopt = argv;
241e6541fdeSIntel 
242e6541fdeSIntel 	while ((opt = getopt_long(argc, argvopt, "p:", lgopts, &option_index)) != EOF) {
243e6541fdeSIntel 		switch (opt) {
244e6541fdeSIntel 		case 'p':
245e6541fdeSIntel 			port_mask = parse_portmask(optarg);
246e6541fdeSIntel 			if (port_mask == 0) {
247e6541fdeSIntel 				printf("invalid port mask (null port mask)\n");
248e6541fdeSIntel 				print_usage(prgname);
249e6541fdeSIntel 				return -1;
250e6541fdeSIntel 			}
251e6541fdeSIntel 
252e6541fdeSIntel 			for (i = 0, mask = 1; i < 64; i ++, mask <<= 1){
253e6541fdeSIntel 				if (mask & port_mask){
254e6541fdeSIntel 					port_rx = i;
255e6541fdeSIntel 					port_mask &= ~ mask;
256e6541fdeSIntel 					break;
257e6541fdeSIntel 				}
258e6541fdeSIntel 			}
259e6541fdeSIntel 
260e6541fdeSIntel 			for (i = 0, mask = 1; i < 64; i ++, mask <<= 1){
261e6541fdeSIntel 				if (mask & port_mask){
262e6541fdeSIntel 					port_tx = i;
263e6541fdeSIntel 					port_mask &= ~ mask;
264e6541fdeSIntel 					break;
265e6541fdeSIntel 				}
266e6541fdeSIntel 			}
267e6541fdeSIntel 
268e6541fdeSIntel 			if (port_mask != 0) {
269e6541fdeSIntel 				printf("invalid port mask (more than 2 ports)\n");
270e6541fdeSIntel 				print_usage(prgname);
271e6541fdeSIntel 				return -1;
272e6541fdeSIntel 			}
273e6541fdeSIntel 			break;
274e6541fdeSIntel 
275e6541fdeSIntel 		default:
276e6541fdeSIntel 			print_usage(prgname);
277e6541fdeSIntel 			return -1;
278e6541fdeSIntel 		}
279e6541fdeSIntel 	}
280e6541fdeSIntel 
281e6541fdeSIntel 	if (optind <= 1) {
282e6541fdeSIntel 		print_usage(prgname);
283e6541fdeSIntel 		return -1;
284e6541fdeSIntel 	}
285e6541fdeSIntel 
286e6541fdeSIntel 	argv[optind-1] = prgname;
287e6541fdeSIntel 
2889d5ca532SKeith Wiles 	optind = 1; /* reset getopt lib */
289e6541fdeSIntel 	return 0;
290e6541fdeSIntel }
291e6541fdeSIntel 
292e6541fdeSIntel int
main(int argc,char ** argv)29398a16481SDavid Marchand main(int argc, char **argv)
294e6541fdeSIntel {
295e6541fdeSIntel 	uint32_t lcore_id;
29660efb44fSRoman Zhukov 	uint16_t nb_rxd = NIC_RX_QUEUE_DESC;
29760efb44fSRoman Zhukov 	uint16_t nb_txd = NIC_TX_QUEUE_DESC;
2980b8fccaaSShahaf Shuler 	struct rte_eth_conf conf;
2990b8fccaaSShahaf Shuler 	struct rte_eth_rxconf rxq_conf;
3000b8fccaaSShahaf Shuler 	struct rte_eth_txconf txq_conf;
3010b8fccaaSShahaf Shuler 	struct rte_eth_dev_info dev_info;
302e6541fdeSIntel 	int ret;
303e6541fdeSIntel 
304e6541fdeSIntel 	/* EAL init */
305e6541fdeSIntel 	ret = rte_eal_init(argc, argv);
306e6541fdeSIntel 	if (ret < 0)
307e6541fdeSIntel 		rte_exit(EXIT_FAILURE, "Invalid EAL parameters\n");
308e6541fdeSIntel 	argc -= ret;
309e6541fdeSIntel 	argv += ret;
310e6541fdeSIntel 	if (rte_lcore_count() != 1) {
311e6541fdeSIntel 		rte_exit(EXIT_FAILURE, "This application does not accept more than one core. "
312e6541fdeSIntel 		"Please adjust the \"-c COREMASK\" parameter accordingly.\n");
313e6541fdeSIntel 	}
314e6541fdeSIntel 
315e6541fdeSIntel 	/* Application non-EAL arguments parse */
316e6541fdeSIntel 	ret = parse_args(argc, argv);
317e6541fdeSIntel 	if (ret < 0)
318e6541fdeSIntel 		rte_exit(EXIT_FAILURE, "Invalid input arguments\n");
319e6541fdeSIntel 
320e6541fdeSIntel 	/* Buffer pool init */
321ea0c20eaSOlivier Matz 	pool = rte_pktmbuf_pool_create("pool", NB_MBUF, MEMPOOL_CACHE_SIZE,
322824cb29cSKonstantin Ananyev 		0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
323e6541fdeSIntel 	if (pool == NULL)
324e6541fdeSIntel 		rte_exit(EXIT_FAILURE, "Buffer pool creation error\n");
325e6541fdeSIntel 
326e6541fdeSIntel 	/* NIC init */
3270b8fccaaSShahaf Shuler 	conf = port_conf;
328089e5ed7SIvan Ilchenko 
329089e5ed7SIvan Ilchenko 	ret = rte_eth_dev_info_get(port_rx, &dev_info);
330089e5ed7SIvan Ilchenko 	if (ret != 0)
331089e5ed7SIvan Ilchenko 		rte_exit(EXIT_FAILURE,
332089e5ed7SIvan Ilchenko 			"Error during getting device (port %u) info: %s\n",
333089e5ed7SIvan Ilchenko 			port_rx, strerror(-ret));
334089e5ed7SIvan Ilchenko 
335295968d1SFerruh Yigit 	if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE)
336295968d1SFerruh Yigit 		conf.txmode.offloads |= RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
3374f5701f2SFerruh Yigit 
3384f5701f2SFerruh Yigit 	conf.rx_adv_conf.rss_conf.rss_hf &= dev_info.flow_type_rss_offloads;
3394f5701f2SFerruh Yigit 	if (conf.rx_adv_conf.rss_conf.rss_hf !=
3404f5701f2SFerruh Yigit 			port_conf.rx_adv_conf.rss_conf.rss_hf) {
3414f5701f2SFerruh Yigit 		printf("Port %u modified RSS hash function based on hardware support,"
3424f5701f2SFerruh Yigit 			"requested:%#"PRIx64" configured:%#"PRIx64"\n",
3434f5701f2SFerruh Yigit 			port_rx,
3444f5701f2SFerruh Yigit 			port_conf.rx_adv_conf.rss_conf.rss_hf,
3454f5701f2SFerruh Yigit 			conf.rx_adv_conf.rss_conf.rss_hf);
3464f5701f2SFerruh Yigit 	}
3474f5701f2SFerruh Yigit 
3480b8fccaaSShahaf Shuler 	ret = rte_eth_dev_configure(port_rx, 1, 1, &conf);
349e6541fdeSIntel 	if (ret < 0)
350e6541fdeSIntel 		rte_exit(EXIT_FAILURE, "Port %d configuration error (%d)\n", port_rx, ret);
351e6541fdeSIntel 
35260efb44fSRoman Zhukov 	ret = rte_eth_dev_adjust_nb_rx_tx_desc(port_rx, &nb_rxd, &nb_txd);
35360efb44fSRoman Zhukov 	if (ret < 0)
35460efb44fSRoman Zhukov 		rte_exit(EXIT_FAILURE, "Port %d adjust number of descriptors error (%d)\n",
35560efb44fSRoman Zhukov 				port_rx, ret);
35660efb44fSRoman Zhukov 
3570b8fccaaSShahaf Shuler 	rxq_conf = dev_info.default_rxconf;
3580b8fccaaSShahaf Shuler 	rxq_conf.offloads = conf.rxmode.offloads;
35960efb44fSRoman Zhukov 	ret = rte_eth_rx_queue_setup(port_rx, NIC_RX_QUEUE, nb_rxd,
36081f7ecd9SPablo de Lara 				rte_eth_dev_socket_id(port_rx),
3610b8fccaaSShahaf Shuler 				&rxq_conf, pool);
362e6541fdeSIntel 	if (ret < 0)
363e6541fdeSIntel 		rte_exit(EXIT_FAILURE, "Port %d RX queue setup error (%d)\n", port_rx, ret);
364e6541fdeSIntel 
3650b8fccaaSShahaf Shuler 	txq_conf = dev_info.default_txconf;
3660b8fccaaSShahaf Shuler 	txq_conf.offloads = conf.txmode.offloads;
36760efb44fSRoman Zhukov 	ret = rte_eth_tx_queue_setup(port_rx, NIC_TX_QUEUE, nb_txd,
36881f7ecd9SPablo de Lara 				rte_eth_dev_socket_id(port_rx),
3690b8fccaaSShahaf Shuler 				&txq_conf);
370e6541fdeSIntel 	if (ret < 0)
371e6541fdeSIntel 	rte_exit(EXIT_FAILURE, "Port %d TX queue setup error (%d)\n", port_rx, ret);
372e6541fdeSIntel 
3730b8fccaaSShahaf Shuler 	conf = port_conf;
374089e5ed7SIvan Ilchenko 
375089e5ed7SIvan Ilchenko 	ret = rte_eth_dev_info_get(port_tx, &dev_info);
376089e5ed7SIvan Ilchenko 	if (ret != 0)
377089e5ed7SIvan Ilchenko 		rte_exit(EXIT_FAILURE,
378089e5ed7SIvan Ilchenko 			"Error during getting device (port %u) info: %s\n",
379089e5ed7SIvan Ilchenko 			port_tx, strerror(-ret));
380089e5ed7SIvan Ilchenko 
381295968d1SFerruh Yigit 	if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE)
382295968d1SFerruh Yigit 		conf.txmode.offloads |= RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
3834f5701f2SFerruh Yigit 
3844f5701f2SFerruh Yigit 	conf.rx_adv_conf.rss_conf.rss_hf &= dev_info.flow_type_rss_offloads;
3854f5701f2SFerruh Yigit 	if (conf.rx_adv_conf.rss_conf.rss_hf !=
3864f5701f2SFerruh Yigit 			port_conf.rx_adv_conf.rss_conf.rss_hf) {
3874f5701f2SFerruh Yigit 		printf("Port %u modified RSS hash function based on hardware support,"
3884f5701f2SFerruh Yigit 			"requested:%#"PRIx64" configured:%#"PRIx64"\n",
3894f5701f2SFerruh Yigit 			port_tx,
3904f5701f2SFerruh Yigit 			port_conf.rx_adv_conf.rss_conf.rss_hf,
3914f5701f2SFerruh Yigit 			conf.rx_adv_conf.rss_conf.rss_hf);
3924f5701f2SFerruh Yigit 	}
3934f5701f2SFerruh Yigit 
3940b8fccaaSShahaf Shuler 	ret = rte_eth_dev_configure(port_tx, 1, 1, &conf);
395e6541fdeSIntel 	if (ret < 0)
396e6541fdeSIntel 		rte_exit(EXIT_FAILURE, "Port %d configuration error (%d)\n", port_tx, ret);
397e6541fdeSIntel 
39860efb44fSRoman Zhukov 	nb_rxd = NIC_RX_QUEUE_DESC;
39960efb44fSRoman Zhukov 	nb_txd = NIC_TX_QUEUE_DESC;
40060efb44fSRoman Zhukov 	ret = rte_eth_dev_adjust_nb_rx_tx_desc(port_tx, &nb_rxd, &nb_txd);
40160efb44fSRoman Zhukov 	if (ret < 0)
40260efb44fSRoman Zhukov 		rte_exit(EXIT_FAILURE, "Port %d adjust number of descriptors error (%d)\n",
40360efb44fSRoman Zhukov 				port_tx, ret);
40460efb44fSRoman Zhukov 
4050b8fccaaSShahaf Shuler 	rxq_conf = dev_info.default_rxconf;
4060b8fccaaSShahaf Shuler 	rxq_conf.offloads = conf.rxmode.offloads;
40760efb44fSRoman Zhukov 	ret = rte_eth_rx_queue_setup(port_tx, NIC_RX_QUEUE, nb_rxd,
40881f7ecd9SPablo de Lara 				rte_eth_dev_socket_id(port_tx),
40981f7ecd9SPablo de Lara 				NULL, pool);
410e6541fdeSIntel 	if (ret < 0)
411e6541fdeSIntel 		rte_exit(EXIT_FAILURE, "Port %d RX queue setup error (%d)\n", port_tx, ret);
412e6541fdeSIntel 
4130b8fccaaSShahaf Shuler 	txq_conf = dev_info.default_txconf;
4140b8fccaaSShahaf Shuler 	txq_conf.offloads = conf.txmode.offloads;
41560efb44fSRoman Zhukov 	ret = rte_eth_tx_queue_setup(port_tx, NIC_TX_QUEUE, nb_txd,
41681f7ecd9SPablo de Lara 				rte_eth_dev_socket_id(port_tx),
41781f7ecd9SPablo de Lara 				NULL);
418e6541fdeSIntel 	if (ret < 0)
419e6541fdeSIntel 		rte_exit(EXIT_FAILURE, "Port %d TX queue setup error (%d)\n", port_tx, ret);
420e6541fdeSIntel 
421e2366e74STomasz Kulasek 	tx_buffer = rte_zmalloc_socket("tx_buffer",
422daa02b5cSOlivier Matz 			RTE_ETH_TX_BUFFER_SIZE(RTE_MBUF_F_TX_BURST_MAX), 0,
423e2366e74STomasz Kulasek 			rte_eth_dev_socket_id(port_tx));
424e2366e74STomasz Kulasek 	if (tx_buffer == NULL)
425e2366e74STomasz Kulasek 		rte_exit(EXIT_FAILURE, "Port %d TX buffer allocation error\n",
426e2366e74STomasz Kulasek 				port_tx);
427e2366e74STomasz Kulasek 
428daa02b5cSOlivier Matz 	rte_eth_tx_buffer_init(tx_buffer, RTE_MBUF_F_TX_BURST_MAX);
429e2366e74STomasz Kulasek 
430e6541fdeSIntel 	ret = rte_eth_dev_start(port_rx);
431e6541fdeSIntel 	if (ret < 0)
432e6541fdeSIntel 		rte_exit(EXIT_FAILURE, "Port %d start error (%d)\n", port_rx, ret);
433e6541fdeSIntel 
434e6541fdeSIntel 	ret = rte_eth_dev_start(port_tx);
435e6541fdeSIntel 	if (ret < 0)
436e6541fdeSIntel 		rte_exit(EXIT_FAILURE, "Port %d start error (%d)\n", port_tx, ret);
437e6541fdeSIntel 
438f430bbceSIvan Ilchenko 	ret = rte_eth_promiscuous_enable(port_rx);
439f430bbceSIvan Ilchenko 	if (ret != 0)
440f430bbceSIvan Ilchenko 		rte_exit(EXIT_FAILURE,
441f430bbceSIvan Ilchenko 			"Port %d promiscuous mode enable error (%s)\n",
442f430bbceSIvan Ilchenko 			port_rx, rte_strerror(-ret));
443e6541fdeSIntel 
444f430bbceSIvan Ilchenko 	ret = rte_eth_promiscuous_enable(port_tx);
445f430bbceSIvan Ilchenko 	if (ret != 0)
446f430bbceSIvan Ilchenko 		rte_exit(EXIT_FAILURE,
447f430bbceSIvan Ilchenko 			"Port %d promiscuous mode enable error (%s)\n",
448f430bbceSIvan Ilchenko 			port_rx, rte_strerror(-ret));
449e6541fdeSIntel 
450e6541fdeSIntel 	/* App configuration */
451e752649cSSlawomir Mrozowicz 	ret = app_configure_flow_table();
452e752649cSSlawomir Mrozowicz 	if (ret < 0)
453e752649cSSlawomir Mrozowicz 		rte_exit(EXIT_FAILURE, "Invalid configure flow table\n");
454e6541fdeSIntel 
455e6541fdeSIntel 	/* Launch per-lcore init on every lcore */
456cb056611SStephen Hemminger 	rte_eal_mp_remote_launch(main_loop, NULL, CALL_MAIN);
457cb056611SStephen Hemminger 	RTE_LCORE_FOREACH_WORKER(lcore_id) {
458e6541fdeSIntel 		if (rte_eal_wait_lcore(lcore_id) < 0)
459e6541fdeSIntel 			return -1;
460e6541fdeSIntel 	}
461e6541fdeSIntel 
46210aa3757SChengchang Tang 	/* clean up the EAL */
46310aa3757SChengchang Tang 	rte_eal_cleanup();
46410aa3757SChengchang Tang 
465e6541fdeSIntel 	return 0;
466e6541fdeSIntel }
467