1d30ea906Sjfb8856606 /* SPDX-License-Identifier: BSD-3-Clause
2d30ea906Sjfb8856606 * Copyright(c) 2010-2014 Intel Corporation
3a9643ea8Slogwang */
4a9643ea8Slogwang
5a9643ea8Slogwang #include <stdio.h>
6a9643ea8Slogwang #include <stdlib.h>
7a9643ea8Slogwang #include <stdint.h>
8a9643ea8Slogwang #include <inttypes.h>
9a9643ea8Slogwang #include <sys/types.h>
10a9643ea8Slogwang #include <string.h>
11a9643ea8Slogwang #include <sys/queue.h>
12a9643ea8Slogwang #include <stdarg.h>
13a9643ea8Slogwang #include <errno.h>
14a9643ea8Slogwang #include <getopt.h>
15a9643ea8Slogwang
16a9643ea8Slogwang #include <rte_common.h>
17a9643ea8Slogwang #include <rte_byteorder.h>
18a9643ea8Slogwang #include <rte_log.h>
19a9643ea8Slogwang #include <rte_memory.h>
20a9643ea8Slogwang #include <rte_memcpy.h>
21a9643ea8Slogwang #include <rte_eal.h>
22a9643ea8Slogwang #include <rte_launch.h>
23a9643ea8Slogwang #include <rte_atomic.h>
24a9643ea8Slogwang #include <rte_cycles.h>
25a9643ea8Slogwang #include <rte_prefetch.h>
26a9643ea8Slogwang #include <rte_lcore.h>
27a9643ea8Slogwang #include <rte_per_lcore.h>
28a9643ea8Slogwang #include <rte_branch_prediction.h>
29a9643ea8Slogwang #include <rte_interrupts.h>
30a9643ea8Slogwang #include <rte_random.h>
31a9643ea8Slogwang #include <rte_debug.h>
32a9643ea8Slogwang #include <rte_ether.h>
33a9643ea8Slogwang #include <rte_ethdev.h>
34a9643ea8Slogwang #include <rte_mempool.h>
35a9643ea8Slogwang #include <rte_mbuf.h>
36a9643ea8Slogwang #include <rte_malloc.h>
37a9643ea8Slogwang #include <rte_fbk_hash.h>
38a9643ea8Slogwang #include <rte_ip.h>
39a9643ea8Slogwang
40a9643ea8Slogwang #define RTE_LOGTYPE_IPv4_MULTICAST RTE_LOGTYPE_USER1
41a9643ea8Slogwang
42a9643ea8Slogwang #define MAX_PORTS 16
43a9643ea8Slogwang
44a9643ea8Slogwang #define MCAST_CLONE_PORTS 2
45a9643ea8Slogwang #define MCAST_CLONE_SEGS 2
46a9643ea8Slogwang
47a9643ea8Slogwang #define PKT_MBUF_DATA_SIZE RTE_MBUF_DEFAULT_BUF_SIZE
48a9643ea8Slogwang #define NB_PKT_MBUF 8192
49a9643ea8Slogwang
50a9643ea8Slogwang #define HDR_MBUF_DATA_SIZE (2 * RTE_PKTMBUF_HEADROOM)
51a9643ea8Slogwang #define NB_HDR_MBUF (NB_PKT_MBUF * MAX_PORTS)
52a9643ea8Slogwang
53a9643ea8Slogwang #define NB_CLONE_MBUF (NB_PKT_MBUF * MCAST_CLONE_PORTS * MCAST_CLONE_SEGS * 2)
54a9643ea8Slogwang
55a9643ea8Slogwang /* allow max jumbo frame 9.5 KB */
56a9643ea8Slogwang #define JUMBO_FRAME_MAX_SIZE 0x2600
57a9643ea8Slogwang
58a9643ea8Slogwang #define MAX_PKT_BURST 32
59a9643ea8Slogwang #define BURST_TX_DRAIN_US 100 /* TX drain every ~100us */
60a9643ea8Slogwang
61a9643ea8Slogwang /* Configure how many packets ahead to prefetch, when reading packets */
62a9643ea8Slogwang #define PREFETCH_OFFSET 3
63a9643ea8Slogwang
64a9643ea8Slogwang /*
65a9643ea8Slogwang * Construct Ethernet multicast address from IPv4 multicast address.
66a9643ea8Slogwang * Citing RFC 1112, section 6.4:
67a9643ea8Slogwang * "An IP host group address is mapped to an Ethernet multicast address
68a9643ea8Slogwang * by placing the low-order 23-bits of the IP address into the low-order
69a9643ea8Slogwang * 23 bits of the Ethernet multicast address 01-00-5E-00-00-00 (hex)."
70a9643ea8Slogwang */
71a9643ea8Slogwang #define ETHER_ADDR_FOR_IPV4_MCAST(x) \
72a9643ea8Slogwang (rte_cpu_to_be_64(0x01005e000000ULL | ((x) & 0x7fffff)) >> 16)
73a9643ea8Slogwang
74a9643ea8Slogwang /*
75a9643ea8Slogwang * Configurable number of RX/TX ring descriptors
76a9643ea8Slogwang */
77d30ea906Sjfb8856606 #define RTE_TEST_RX_DESC_DEFAULT 1024
78d30ea906Sjfb8856606 #define RTE_TEST_TX_DESC_DEFAULT 1024
79a9643ea8Slogwang static uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT;
80a9643ea8Slogwang static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT;
81a9643ea8Slogwang
82a9643ea8Slogwang /* ethernet addresses of ports */
834418919fSjohnjiang static struct rte_ether_addr ports_eth_addr[MAX_PORTS];
84a9643ea8Slogwang
85a9643ea8Slogwang /* mask of enabled ports */
86a9643ea8Slogwang static uint32_t enabled_port_mask = 0;
87a9643ea8Slogwang
882bfe3f2eSlogwang static uint16_t nb_ports;
89a9643ea8Slogwang
90a9643ea8Slogwang static int rx_queue_per_lcore = 1;
91a9643ea8Slogwang
92a9643ea8Slogwang struct mbuf_table {
93a9643ea8Slogwang uint16_t len;
94a9643ea8Slogwang struct rte_mbuf *m_table[MAX_PKT_BURST];
95a9643ea8Slogwang };
96a9643ea8Slogwang
97a9643ea8Slogwang #define MAX_RX_QUEUE_PER_LCORE 16
98a9643ea8Slogwang #define MAX_TX_QUEUE_PER_PORT 16
99a9643ea8Slogwang struct lcore_queue_conf {
100a9643ea8Slogwang uint64_t tx_tsc;
101a9643ea8Slogwang uint16_t n_rx_queue;
102a9643ea8Slogwang uint8_t rx_queue_list[MAX_RX_QUEUE_PER_LCORE];
103a9643ea8Slogwang uint16_t tx_queue_id[MAX_PORTS];
104a9643ea8Slogwang struct mbuf_table tx_mbufs[MAX_PORTS];
105a9643ea8Slogwang } __rte_cache_aligned;
106a9643ea8Slogwang static struct lcore_queue_conf lcore_queue_conf[RTE_MAX_LCORE];
107a9643ea8Slogwang
1082bfe3f2eSlogwang static struct rte_eth_conf port_conf = {
109a9643ea8Slogwang .rxmode = {
110a9643ea8Slogwang .max_rx_pkt_len = JUMBO_FRAME_MAX_SIZE,
111a9643ea8Slogwang .split_hdr_size = 0,
112d30ea906Sjfb8856606 .offloads = DEV_RX_OFFLOAD_JUMBO_FRAME,
113a9643ea8Slogwang },
114a9643ea8Slogwang .txmode = {
115a9643ea8Slogwang .mq_mode = ETH_MQ_TX_NONE,
116d30ea906Sjfb8856606 .offloads = DEV_TX_OFFLOAD_MULTI_SEGS,
117a9643ea8Slogwang },
118a9643ea8Slogwang };
119a9643ea8Slogwang
120a9643ea8Slogwang static struct rte_mempool *packet_pool, *header_pool, *clone_pool;
121a9643ea8Slogwang
122a9643ea8Slogwang
123a9643ea8Slogwang /* Multicast */
124a9643ea8Slogwang static struct rte_fbk_hash_params mcast_hash_params = {
125a9643ea8Slogwang .name = "MCAST_HASH",
126a9643ea8Slogwang .entries = 1024,
127a9643ea8Slogwang .entries_per_bucket = 4,
128a9643ea8Slogwang .socket_id = 0,
129a9643ea8Slogwang .hash_func = NULL,
130a9643ea8Slogwang .init_val = 0,
131a9643ea8Slogwang };
132a9643ea8Slogwang
133a9643ea8Slogwang struct rte_fbk_hash_table *mcast_hash = NULL;
134a9643ea8Slogwang
135a9643ea8Slogwang struct mcast_group_params {
136a9643ea8Slogwang uint32_t ip;
137a9643ea8Slogwang uint16_t port_mask;
138a9643ea8Slogwang };
139a9643ea8Slogwang
140a9643ea8Slogwang static struct mcast_group_params mcast_group_table[] = {
1414418919fSjohnjiang {RTE_IPV4(224,0,0,101), 0x1},
1424418919fSjohnjiang {RTE_IPV4(224,0,0,102), 0x2},
1434418919fSjohnjiang {RTE_IPV4(224,0,0,103), 0x3},
1444418919fSjohnjiang {RTE_IPV4(224,0,0,104), 0x4},
1454418919fSjohnjiang {RTE_IPV4(224,0,0,105), 0x5},
1464418919fSjohnjiang {RTE_IPV4(224,0,0,106), 0x6},
1474418919fSjohnjiang {RTE_IPV4(224,0,0,107), 0x7},
1484418919fSjohnjiang {RTE_IPV4(224,0,0,108), 0x8},
1494418919fSjohnjiang {RTE_IPV4(224,0,0,109), 0x9},
1504418919fSjohnjiang {RTE_IPV4(224,0,0,110), 0xA},
1514418919fSjohnjiang {RTE_IPV4(224,0,0,111), 0xB},
1524418919fSjohnjiang {RTE_IPV4(224,0,0,112), 0xC},
1534418919fSjohnjiang {RTE_IPV4(224,0,0,113), 0xD},
1544418919fSjohnjiang {RTE_IPV4(224,0,0,114), 0xE},
1554418919fSjohnjiang {RTE_IPV4(224,0,0,115), 0xF},
156a9643ea8Slogwang };
157a9643ea8Slogwang
158a9643ea8Slogwang /* Send burst of packets on an output interface */
159a9643ea8Slogwang static void
send_burst(struct lcore_queue_conf * qconf,uint16_t port)1602bfe3f2eSlogwang send_burst(struct lcore_queue_conf *qconf, uint16_t port)
161a9643ea8Slogwang {
162a9643ea8Slogwang struct rte_mbuf **m_table;
163a9643ea8Slogwang uint16_t n, queueid;
164a9643ea8Slogwang int ret;
165a9643ea8Slogwang
166a9643ea8Slogwang queueid = qconf->tx_queue_id[port];
167a9643ea8Slogwang m_table = (struct rte_mbuf **)qconf->tx_mbufs[port].m_table;
168a9643ea8Slogwang n = qconf->tx_mbufs[port].len;
169a9643ea8Slogwang
170a9643ea8Slogwang ret = rte_eth_tx_burst(port, queueid, m_table, n);
171a9643ea8Slogwang while (unlikely (ret < n)) {
172a9643ea8Slogwang rte_pktmbuf_free(m_table[ret]);
173a9643ea8Slogwang ret++;
174a9643ea8Slogwang }
175a9643ea8Slogwang
176a9643ea8Slogwang qconf->tx_mbufs[port].len = 0;
177a9643ea8Slogwang }
178a9643ea8Slogwang
179a9643ea8Slogwang /* Get number of bits set. */
180a9643ea8Slogwang static inline uint32_t
bitcnt(uint32_t v)181a9643ea8Slogwang bitcnt(uint32_t v)
182a9643ea8Slogwang {
183a9643ea8Slogwang uint32_t n;
184a9643ea8Slogwang
185a9643ea8Slogwang for (n = 0; v != 0; v &= v - 1, n++)
186a9643ea8Slogwang ;
187a9643ea8Slogwang
188a9643ea8Slogwang return n;
189a9643ea8Slogwang }
190a9643ea8Slogwang
191a9643ea8Slogwang /**
192a9643ea8Slogwang * Create the output multicast packet based on the given input packet.
193a9643ea8Slogwang * There are two approaches for creating outgoing packet, though both
194a9643ea8Slogwang * are based on data zero-copy idea, they differ in few details:
195a9643ea8Slogwang * First one creates a clone of the input packet, e.g - walk though all
196a9643ea8Slogwang * segments of the input packet, and for each of them create a new packet
197a9643ea8Slogwang * mbuf and attach that new mbuf to the segment (refer to rte_pktmbuf_clone()
198a9643ea8Slogwang * for more details). Then new mbuf is allocated for the packet header
199a9643ea8Slogwang * and is prepended to the 'clone' mbuf.
200a9643ea8Slogwang * Second approach doesn't make a clone, it just increment refcnt for all
201a9643ea8Slogwang * input packet segments. Then it allocates new mbuf for the packet header
202a9643ea8Slogwang * and prepends it to the input packet.
203a9643ea8Slogwang * Basically first approach reuses only input packet's data, but creates
204a9643ea8Slogwang * it's own copy of packet's metadata. Second approach reuses both input's
205a9643ea8Slogwang * packet data and metadata.
206a9643ea8Slogwang * The advantage of first approach - is that each outgoing packet has it's
207a9643ea8Slogwang * own copy of metadata, so we can safely modify data pointer of the
208a9643ea8Slogwang * input packet. That allows us to skip creation if the output packet for
209a9643ea8Slogwang * the last destination port, but instead modify input packet's header inplace,
210a9643ea8Slogwang * e.g: for N destination ports we need to invoke mcast_out_pkt (N-1) times.
211a9643ea8Slogwang * The advantage of second approach - less work for each outgoing packet,
212a9643ea8Slogwang * e.g: we skip "clone" operation completely. Though it comes with a price -
213a9643ea8Slogwang * input packet's metadata has to be intact. So for N destination ports we
214a9643ea8Slogwang * need to invoke mcast_out_pkt N times.
215a9643ea8Slogwang * So for small number of outgoing ports (and segments in the input packet)
216a9643ea8Slogwang * first approach will be faster.
217a9643ea8Slogwang * As number of outgoing ports (and/or input segments) will grow,
218a9643ea8Slogwang * second way will become more preferable.
219a9643ea8Slogwang *
220a9643ea8Slogwang * @param pkt
221a9643ea8Slogwang * Input packet mbuf.
222a9643ea8Slogwang * @param use_clone
223a9643ea8Slogwang * Control which of the two approaches described above should be used:
224a9643ea8Slogwang * - 0 - use second approach:
225a9643ea8Slogwang * Don't "clone" input packet.
226a9643ea8Slogwang * Prepend new header directly to the input packet
227a9643ea8Slogwang * - 1 - use first approach:
228a9643ea8Slogwang * Make a "clone" of input packet first.
229a9643ea8Slogwang * Prepend new header to the clone of the input packet
230a9643ea8Slogwang * @return
231a9643ea8Slogwang * - The pointer to the new outgoing packet.
232a9643ea8Slogwang * - NULL if operation failed.
233a9643ea8Slogwang */
234a9643ea8Slogwang static inline struct rte_mbuf *
mcast_out_pkt(struct rte_mbuf * pkt,int use_clone)235a9643ea8Slogwang mcast_out_pkt(struct rte_mbuf *pkt, int use_clone)
236a9643ea8Slogwang {
237a9643ea8Slogwang struct rte_mbuf *hdr;
238a9643ea8Slogwang
239a9643ea8Slogwang /* Create new mbuf for the header. */
240a9643ea8Slogwang if (unlikely ((hdr = rte_pktmbuf_alloc(header_pool)) == NULL))
241a9643ea8Slogwang return NULL;
242a9643ea8Slogwang
243a9643ea8Slogwang /* If requested, then make a new clone packet. */
244a9643ea8Slogwang if (use_clone != 0 &&
245a9643ea8Slogwang unlikely ((pkt = rte_pktmbuf_clone(pkt, clone_pool)) == NULL)) {
246a9643ea8Slogwang rte_pktmbuf_free(hdr);
247a9643ea8Slogwang return NULL;
248a9643ea8Slogwang }
249a9643ea8Slogwang
250a9643ea8Slogwang /* prepend new header */
251a9643ea8Slogwang hdr->next = pkt;
252a9643ea8Slogwang
253a9643ea8Slogwang /* update header's fields */
254a9643ea8Slogwang hdr->pkt_len = (uint16_t)(hdr->data_len + pkt->pkt_len);
2552bfe3f2eSlogwang hdr->nb_segs = pkt->nb_segs + 1;
256a9643ea8Slogwang
257a9643ea8Slogwang __rte_mbuf_sanity_check(hdr, 1);
258a9643ea8Slogwang return hdr;
259a9643ea8Slogwang }
260a9643ea8Slogwang
261a9643ea8Slogwang /*
262a9643ea8Slogwang * Write new Ethernet header to the outgoing packet,
263a9643ea8Slogwang * and put it into the outgoing queue for the given port.
264a9643ea8Slogwang */
265a9643ea8Slogwang static inline void
mcast_send_pkt(struct rte_mbuf * pkt,struct rte_ether_addr * dest_addr,struct lcore_queue_conf * qconf,uint16_t port)2664418919fSjohnjiang mcast_send_pkt(struct rte_mbuf *pkt, struct rte_ether_addr *dest_addr,
2672bfe3f2eSlogwang struct lcore_queue_conf *qconf, uint16_t port)
268a9643ea8Slogwang {
2694418919fSjohnjiang struct rte_ether_hdr *ethdr;
270a9643ea8Slogwang uint16_t len;
271a9643ea8Slogwang
272a9643ea8Slogwang /* Construct Ethernet header. */
2734418919fSjohnjiang ethdr = (struct rte_ether_hdr *)
2744418919fSjohnjiang rte_pktmbuf_prepend(pkt, (uint16_t)sizeof(*ethdr));
275a9643ea8Slogwang RTE_ASSERT(ethdr != NULL);
276a9643ea8Slogwang
2774418919fSjohnjiang rte_ether_addr_copy(dest_addr, ðdr->d_addr);
2784418919fSjohnjiang rte_ether_addr_copy(&ports_eth_addr[port], ðdr->s_addr);
2794418919fSjohnjiang ethdr->ether_type = rte_be_to_cpu_16(RTE_ETHER_TYPE_IPV4);
280a9643ea8Slogwang
281a9643ea8Slogwang /* Put new packet into the output queue */
282a9643ea8Slogwang len = qconf->tx_mbufs[port].len;
283a9643ea8Slogwang qconf->tx_mbufs[port].m_table[len] = pkt;
284a9643ea8Slogwang qconf->tx_mbufs[port].len = ++len;
285a9643ea8Slogwang
286a9643ea8Slogwang /* Transmit packets */
287a9643ea8Slogwang if (unlikely(MAX_PKT_BURST == len))
288a9643ea8Slogwang send_burst(qconf, port);
289a9643ea8Slogwang }
290a9643ea8Slogwang
291a9643ea8Slogwang /* Multicast forward of the input packet */
292a9643ea8Slogwang static inline void
mcast_forward(struct rte_mbuf * m,struct lcore_queue_conf * qconf)293a9643ea8Slogwang mcast_forward(struct rte_mbuf *m, struct lcore_queue_conf *qconf)
294a9643ea8Slogwang {
295a9643ea8Slogwang struct rte_mbuf *mc;
2964418919fSjohnjiang struct rte_ipv4_hdr *iphdr;
297a9643ea8Slogwang uint32_t dest_addr, port_mask, port_num, use_clone;
298a9643ea8Slogwang int32_t hash;
2992bfe3f2eSlogwang uint16_t port;
300a9643ea8Slogwang union {
301a9643ea8Slogwang uint64_t as_int;
3024418919fSjohnjiang struct rte_ether_addr as_addr;
303a9643ea8Slogwang } dst_eth_addr;
304a9643ea8Slogwang
305a9643ea8Slogwang /* Remove the Ethernet header from the input packet */
3064418919fSjohnjiang iphdr = (struct rte_ipv4_hdr *)
3074418919fSjohnjiang rte_pktmbuf_adj(m, (uint16_t)sizeof(struct rte_ether_hdr));
308a9643ea8Slogwang RTE_ASSERT(iphdr != NULL);
309a9643ea8Slogwang
310a9643ea8Slogwang dest_addr = rte_be_to_cpu_32(iphdr->dst_addr);
311a9643ea8Slogwang
312a9643ea8Slogwang /*
313a9643ea8Slogwang * Check that it is a valid multicast address and
314a9643ea8Slogwang * we have some active ports assigned to it.
315a9643ea8Slogwang */
3164418919fSjohnjiang if (!RTE_IS_IPV4_MCAST(dest_addr) ||
317a9643ea8Slogwang (hash = rte_fbk_hash_lookup(mcast_hash, dest_addr)) <= 0 ||
318a9643ea8Slogwang (port_mask = hash & enabled_port_mask) == 0) {
319a9643ea8Slogwang rte_pktmbuf_free(m);
320a9643ea8Slogwang return;
321a9643ea8Slogwang }
322a9643ea8Slogwang
323a9643ea8Slogwang /* Calculate number of destination ports. */
324a9643ea8Slogwang port_num = bitcnt(port_mask);
325a9643ea8Slogwang
326a9643ea8Slogwang /* Should we use rte_pktmbuf_clone() or not. */
327a9643ea8Slogwang use_clone = (port_num <= MCAST_CLONE_PORTS &&
328a9643ea8Slogwang m->nb_segs <= MCAST_CLONE_SEGS);
329a9643ea8Slogwang
330a9643ea8Slogwang /* Mark all packet's segments as referenced port_num times */
331a9643ea8Slogwang if (use_clone == 0)
332a9643ea8Slogwang rte_pktmbuf_refcnt_update(m, (uint16_t)port_num);
333a9643ea8Slogwang
334a9643ea8Slogwang /* construct destination ethernet address */
335a9643ea8Slogwang dst_eth_addr.as_int = ETHER_ADDR_FOR_IPV4_MCAST(dest_addr);
336a9643ea8Slogwang
337a9643ea8Slogwang for (port = 0; use_clone != port_mask; port_mask >>= 1, port++) {
338a9643ea8Slogwang
339a9643ea8Slogwang /* Prepare output packet and send it out. */
340a9643ea8Slogwang if ((port_mask & 1) != 0) {
341a9643ea8Slogwang if (likely ((mc = mcast_out_pkt(m, use_clone)) != NULL))
342a9643ea8Slogwang mcast_send_pkt(mc, &dst_eth_addr.as_addr,
343a9643ea8Slogwang qconf, port);
344a9643ea8Slogwang else if (use_clone == 0)
345a9643ea8Slogwang rte_pktmbuf_free(m);
346a9643ea8Slogwang }
347a9643ea8Slogwang }
348a9643ea8Slogwang
349a9643ea8Slogwang /*
350a9643ea8Slogwang * If we making clone packets, then, for the last destination port,
351a9643ea8Slogwang * we can overwrite input packet's metadata.
352a9643ea8Slogwang */
353a9643ea8Slogwang if (use_clone != 0)
354a9643ea8Slogwang mcast_send_pkt(m, &dst_eth_addr.as_addr, qconf, port);
355a9643ea8Slogwang else
356a9643ea8Slogwang rte_pktmbuf_free(m);
357a9643ea8Slogwang }
358a9643ea8Slogwang
359a9643ea8Slogwang /* Send burst of outgoing packet, if timeout expires. */
360a9643ea8Slogwang static inline void
send_timeout_burst(struct lcore_queue_conf * qconf)361a9643ea8Slogwang send_timeout_burst(struct lcore_queue_conf *qconf)
362a9643ea8Slogwang {
363a9643ea8Slogwang uint64_t cur_tsc;
3642bfe3f2eSlogwang uint16_t portid;
365a9643ea8Slogwang const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) / US_PER_S * BURST_TX_DRAIN_US;
366a9643ea8Slogwang
367a9643ea8Slogwang cur_tsc = rte_rdtsc();
368a9643ea8Slogwang if (likely (cur_tsc < qconf->tx_tsc + drain_tsc))
369a9643ea8Slogwang return;
370a9643ea8Slogwang
371a9643ea8Slogwang for (portid = 0; portid < MAX_PORTS; portid++) {
372a9643ea8Slogwang if (qconf->tx_mbufs[portid].len != 0)
373a9643ea8Slogwang send_burst(qconf, portid);
374a9643ea8Slogwang }
375a9643ea8Slogwang qconf->tx_tsc = cur_tsc;
376a9643ea8Slogwang }
377a9643ea8Slogwang
378a9643ea8Slogwang /* main processing loop */
379a9643ea8Slogwang static int
main_loop(__rte_unused void * dummy)380a9643ea8Slogwang main_loop(__rte_unused void *dummy)
381a9643ea8Slogwang {
382a9643ea8Slogwang struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
383a9643ea8Slogwang unsigned lcore_id;
384a9643ea8Slogwang int i, j, nb_rx;
3852bfe3f2eSlogwang uint16_t portid;
386a9643ea8Slogwang struct lcore_queue_conf *qconf;
387a9643ea8Slogwang
388a9643ea8Slogwang lcore_id = rte_lcore_id();
389a9643ea8Slogwang qconf = &lcore_queue_conf[lcore_id];
390a9643ea8Slogwang
391a9643ea8Slogwang
392a9643ea8Slogwang if (qconf->n_rx_queue == 0) {
393a9643ea8Slogwang RTE_LOG(INFO, IPv4_MULTICAST, "lcore %u has nothing to do\n",
394a9643ea8Slogwang lcore_id);
395a9643ea8Slogwang return 0;
396a9643ea8Slogwang }
397a9643ea8Slogwang
398a9643ea8Slogwang RTE_LOG(INFO, IPv4_MULTICAST, "entering main loop on lcore %u\n",
399a9643ea8Slogwang lcore_id);
400a9643ea8Slogwang
401a9643ea8Slogwang for (i = 0; i < qconf->n_rx_queue; i++) {
402a9643ea8Slogwang
403a9643ea8Slogwang portid = qconf->rx_queue_list[i];
404a9643ea8Slogwang RTE_LOG(INFO, IPv4_MULTICAST, " -- lcoreid=%u portid=%d\n",
4052bfe3f2eSlogwang lcore_id, portid);
406a9643ea8Slogwang }
407a9643ea8Slogwang
408a9643ea8Slogwang while (1) {
409a9643ea8Slogwang
410a9643ea8Slogwang /*
411a9643ea8Slogwang * Read packet from RX queues
412a9643ea8Slogwang */
413a9643ea8Slogwang for (i = 0; i < qconf->n_rx_queue; i++) {
414a9643ea8Slogwang
415a9643ea8Slogwang portid = qconf->rx_queue_list[i];
416a9643ea8Slogwang nb_rx = rte_eth_rx_burst(portid, 0, pkts_burst,
417a9643ea8Slogwang MAX_PKT_BURST);
418a9643ea8Slogwang
419a9643ea8Slogwang /* Prefetch first packets */
420a9643ea8Slogwang for (j = 0; j < PREFETCH_OFFSET && j < nb_rx; j++) {
421a9643ea8Slogwang rte_prefetch0(rte_pktmbuf_mtod(
422a9643ea8Slogwang pkts_burst[j], void *));
423a9643ea8Slogwang }
424a9643ea8Slogwang
425a9643ea8Slogwang /* Prefetch and forward already prefetched packets */
426a9643ea8Slogwang for (j = 0; j < (nb_rx - PREFETCH_OFFSET); j++) {
427a9643ea8Slogwang rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[
428a9643ea8Slogwang j + PREFETCH_OFFSET], void *));
429a9643ea8Slogwang mcast_forward(pkts_burst[j], qconf);
430a9643ea8Slogwang }
431a9643ea8Slogwang
432a9643ea8Slogwang /* Forward remaining prefetched packets */
433a9643ea8Slogwang for (; j < nb_rx; j++) {
434a9643ea8Slogwang mcast_forward(pkts_burst[j], qconf);
435a9643ea8Slogwang }
436a9643ea8Slogwang }
437a9643ea8Slogwang
438a9643ea8Slogwang /* Send out packets from TX queues */
439a9643ea8Slogwang send_timeout_burst(qconf);
440a9643ea8Slogwang }
441a9643ea8Slogwang }
442a9643ea8Slogwang
443a9643ea8Slogwang /* display usage */
444a9643ea8Slogwang static void
print_usage(const char * prgname)445a9643ea8Slogwang print_usage(const char *prgname)
446a9643ea8Slogwang {
447a9643ea8Slogwang printf("%s [EAL options] -- -p PORTMASK [-q NQ]\n"
448a9643ea8Slogwang " -p PORTMASK: hexadecimal bitmask of ports to configure\n"
449a9643ea8Slogwang " -q NQ: number of queue (=ports) per lcore (default is 1)\n",
450a9643ea8Slogwang prgname);
451a9643ea8Slogwang }
452a9643ea8Slogwang
453a9643ea8Slogwang static uint32_t
parse_portmask(const char * portmask)454a9643ea8Slogwang parse_portmask(const char *portmask)
455a9643ea8Slogwang {
456a9643ea8Slogwang char *end = NULL;
457a9643ea8Slogwang unsigned long pm;
458a9643ea8Slogwang
459a9643ea8Slogwang /* parse hexadecimal string */
460a9643ea8Slogwang pm = strtoul(portmask, &end, 16);
461a9643ea8Slogwang if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
462a9643ea8Slogwang return 0;
463a9643ea8Slogwang
464a9643ea8Slogwang return (uint32_t)pm;
465a9643ea8Slogwang }
466a9643ea8Slogwang
467a9643ea8Slogwang static int
parse_nqueue(const char * q_arg)468a9643ea8Slogwang parse_nqueue(const char *q_arg)
469a9643ea8Slogwang {
470a9643ea8Slogwang char *end = NULL;
471a9643ea8Slogwang unsigned long n;
472a9643ea8Slogwang
473a9643ea8Slogwang /* parse numerical string */
474a9643ea8Slogwang errno = 0;
475a9643ea8Slogwang n = strtoul(q_arg, &end, 0);
476a9643ea8Slogwang if (errno != 0 || end == NULL || *end != '\0' ||
477a9643ea8Slogwang n == 0 || n >= MAX_RX_QUEUE_PER_LCORE)
478a9643ea8Slogwang return -1;
479a9643ea8Slogwang
480a9643ea8Slogwang return n;
481a9643ea8Slogwang }
482a9643ea8Slogwang
483a9643ea8Slogwang /* Parse the argument given in the command line of the application */
484a9643ea8Slogwang static int
parse_args(int argc,char ** argv)485a9643ea8Slogwang parse_args(int argc, char **argv)
486a9643ea8Slogwang {
487a9643ea8Slogwang int opt, ret;
488a9643ea8Slogwang char **argvopt;
489a9643ea8Slogwang int option_index;
490a9643ea8Slogwang char *prgname = argv[0];
491a9643ea8Slogwang static struct option lgopts[] = {
492a9643ea8Slogwang {NULL, 0, 0, 0}
493a9643ea8Slogwang };
494a9643ea8Slogwang
495a9643ea8Slogwang argvopt = argv;
496a9643ea8Slogwang
497a9643ea8Slogwang while ((opt = getopt_long(argc, argvopt, "p:q:",
498a9643ea8Slogwang lgopts, &option_index)) != EOF) {
499a9643ea8Slogwang
500a9643ea8Slogwang switch (opt) {
501a9643ea8Slogwang /* portmask */
502a9643ea8Slogwang case 'p':
503a9643ea8Slogwang enabled_port_mask = parse_portmask(optarg);
504a9643ea8Slogwang if (enabled_port_mask == 0) {
505a9643ea8Slogwang printf("invalid portmask\n");
506a9643ea8Slogwang print_usage(prgname);
507a9643ea8Slogwang return -1;
508a9643ea8Slogwang }
509a9643ea8Slogwang break;
510a9643ea8Slogwang
511a9643ea8Slogwang /* nqueue */
512a9643ea8Slogwang case 'q':
513a9643ea8Slogwang rx_queue_per_lcore = parse_nqueue(optarg);
514a9643ea8Slogwang if (rx_queue_per_lcore < 0) {
515a9643ea8Slogwang printf("invalid queue number\n");
516a9643ea8Slogwang print_usage(prgname);
517a9643ea8Slogwang return -1;
518a9643ea8Slogwang }
519a9643ea8Slogwang break;
520a9643ea8Slogwang
521a9643ea8Slogwang default:
522a9643ea8Slogwang print_usage(prgname);
523a9643ea8Slogwang return -1;
524a9643ea8Slogwang }
525a9643ea8Slogwang }
526a9643ea8Slogwang
527a9643ea8Slogwang if (optind >= 0)
528a9643ea8Slogwang argv[optind-1] = prgname;
529a9643ea8Slogwang
530a9643ea8Slogwang ret = optind-1;
5312bfe3f2eSlogwang optind = 1; /* reset getopt lib */
532a9643ea8Slogwang return ret;
533a9643ea8Slogwang }
534a9643ea8Slogwang
535a9643ea8Slogwang static void
print_ethaddr(const char * name,struct rte_ether_addr * eth_addr)5364418919fSjohnjiang print_ethaddr(const char *name, struct rte_ether_addr *eth_addr)
537a9643ea8Slogwang {
5384418919fSjohnjiang char buf[RTE_ETHER_ADDR_FMT_SIZE];
5394418919fSjohnjiang rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
540a9643ea8Slogwang printf("%s%s", name, buf);
541a9643ea8Slogwang }
542a9643ea8Slogwang
543a9643ea8Slogwang static int
init_mcast_hash(void)544a9643ea8Slogwang init_mcast_hash(void)
545a9643ea8Slogwang {
546a9643ea8Slogwang uint32_t i;
547a9643ea8Slogwang
548a9643ea8Slogwang mcast_hash_params.socket_id = rte_socket_id();
549a9643ea8Slogwang mcast_hash = rte_fbk_hash_create(&mcast_hash_params);
550a9643ea8Slogwang if (mcast_hash == NULL){
551a9643ea8Slogwang return -1;
552a9643ea8Slogwang }
553a9643ea8Slogwang
554*2d9fd380Sjfb8856606 for (i = 0; i < RTE_DIM(mcast_group_table); i++) {
555a9643ea8Slogwang if (rte_fbk_hash_add_key(mcast_hash,
556a9643ea8Slogwang mcast_group_table[i].ip,
557a9643ea8Slogwang mcast_group_table[i].port_mask) < 0) {
558a9643ea8Slogwang return -1;
559a9643ea8Slogwang }
560a9643ea8Slogwang }
561a9643ea8Slogwang
562a9643ea8Slogwang return 0;
563a9643ea8Slogwang }
564a9643ea8Slogwang
565a9643ea8Slogwang /* Check the link status of all ports in up to 9s, and print them finally */
566a9643ea8Slogwang static void
check_all_ports_link_status(uint32_t port_mask)567d30ea906Sjfb8856606 check_all_ports_link_status(uint32_t port_mask)
568a9643ea8Slogwang {
569a9643ea8Slogwang #define CHECK_INTERVAL 100 /* 100ms */
570a9643ea8Slogwang #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
5712bfe3f2eSlogwang uint16_t portid;
5722bfe3f2eSlogwang uint8_t count, all_ports_up, print_flag = 0;
573a9643ea8Slogwang struct rte_eth_link link;
5744418919fSjohnjiang int ret;
575*2d9fd380Sjfb8856606 char link_status_text[RTE_ETH_LINK_MAX_STR_LEN];
576a9643ea8Slogwang
577a9643ea8Slogwang printf("\nChecking link status");
578a9643ea8Slogwang fflush(stdout);
579a9643ea8Slogwang for (count = 0; count <= MAX_CHECK_TIME; count++) {
580a9643ea8Slogwang all_ports_up = 1;
581d30ea906Sjfb8856606 RTE_ETH_FOREACH_DEV(portid) {
582a9643ea8Slogwang if ((port_mask & (1 << portid)) == 0)
583a9643ea8Slogwang continue;
584a9643ea8Slogwang memset(&link, 0, sizeof(link));
5854418919fSjohnjiang ret = rte_eth_link_get_nowait(portid, &link);
5864418919fSjohnjiang if (ret < 0) {
5874418919fSjohnjiang all_ports_up = 0;
5884418919fSjohnjiang if (print_flag == 1)
5894418919fSjohnjiang printf("Port %u link get failed: %s\n",
5904418919fSjohnjiang portid, rte_strerror(-ret));
5914418919fSjohnjiang continue;
5924418919fSjohnjiang }
593a9643ea8Slogwang /* print link status if flag set */
594a9643ea8Slogwang if (print_flag == 1) {
595*2d9fd380Sjfb8856606 rte_eth_link_to_str(link_status_text,
596*2d9fd380Sjfb8856606 sizeof(link_status_text),
597*2d9fd380Sjfb8856606 &link);
598*2d9fd380Sjfb8856606 printf("Port %d %s\n", portid,
599*2d9fd380Sjfb8856606 link_status_text);
600a9643ea8Slogwang continue;
601a9643ea8Slogwang }
602a9643ea8Slogwang /* clear all_ports_up flag if any link down */
603a9643ea8Slogwang if (link.link_status == ETH_LINK_DOWN) {
604a9643ea8Slogwang all_ports_up = 0;
605a9643ea8Slogwang break;
606a9643ea8Slogwang }
607a9643ea8Slogwang }
608a9643ea8Slogwang /* after finally printing all link status, get out */
609a9643ea8Slogwang if (print_flag == 1)
610a9643ea8Slogwang break;
611a9643ea8Slogwang
612a9643ea8Slogwang if (all_ports_up == 0) {
613a9643ea8Slogwang printf(".");
614a9643ea8Slogwang fflush(stdout);
615a9643ea8Slogwang rte_delay_ms(CHECK_INTERVAL);
616a9643ea8Slogwang }
617a9643ea8Slogwang
618a9643ea8Slogwang /* set the print_flag if all ports up or timeout */
619a9643ea8Slogwang if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {
620a9643ea8Slogwang print_flag = 1;
621a9643ea8Slogwang printf("done\n");
622a9643ea8Slogwang }
623a9643ea8Slogwang }
624a9643ea8Slogwang }
625a9643ea8Slogwang
626a9643ea8Slogwang int
main(int argc,char ** argv)627a9643ea8Slogwang main(int argc, char **argv)
628a9643ea8Slogwang {
629a9643ea8Slogwang struct lcore_queue_conf *qconf;
630a9643ea8Slogwang struct rte_eth_dev_info dev_info;
631a9643ea8Slogwang struct rte_eth_txconf *txconf;
632a9643ea8Slogwang int ret;
633a9643ea8Slogwang uint16_t queueid;
634a9643ea8Slogwang unsigned lcore_id = 0, rx_lcore_id = 0;
635a9643ea8Slogwang uint32_t n_tx_queue, nb_lcores;
6362bfe3f2eSlogwang uint16_t portid;
637a9643ea8Slogwang
638a9643ea8Slogwang /* init EAL */
639a9643ea8Slogwang ret = rte_eal_init(argc, argv);
640a9643ea8Slogwang if (ret < 0)
641a9643ea8Slogwang rte_exit(EXIT_FAILURE, "Invalid EAL parameters\n");
642a9643ea8Slogwang argc -= ret;
643a9643ea8Slogwang argv += ret;
644a9643ea8Slogwang
645a9643ea8Slogwang /* parse application arguments (after the EAL ones) */
646a9643ea8Slogwang ret = parse_args(argc, argv);
647a9643ea8Slogwang if (ret < 0)
648a9643ea8Slogwang rte_exit(EXIT_FAILURE, "Invalid IPV4_MULTICAST parameters\n");
649a9643ea8Slogwang
650a9643ea8Slogwang /* create the mbuf pools */
651a9643ea8Slogwang packet_pool = rte_pktmbuf_pool_create("packet_pool", NB_PKT_MBUF, 32,
652a9643ea8Slogwang 0, PKT_MBUF_DATA_SIZE, rte_socket_id());
653a9643ea8Slogwang
654a9643ea8Slogwang if (packet_pool == NULL)
655a9643ea8Slogwang rte_exit(EXIT_FAILURE, "Cannot init packet mbuf pool\n");
656a9643ea8Slogwang
657a9643ea8Slogwang header_pool = rte_pktmbuf_pool_create("header_pool", NB_HDR_MBUF, 32,
658a9643ea8Slogwang 0, HDR_MBUF_DATA_SIZE, rte_socket_id());
659a9643ea8Slogwang
660a9643ea8Slogwang if (header_pool == NULL)
661a9643ea8Slogwang rte_exit(EXIT_FAILURE, "Cannot init header mbuf pool\n");
662a9643ea8Slogwang
663a9643ea8Slogwang clone_pool = rte_pktmbuf_pool_create("clone_pool", NB_CLONE_MBUF, 32,
664a9643ea8Slogwang 0, 0, rte_socket_id());
665a9643ea8Slogwang
666a9643ea8Slogwang if (clone_pool == NULL)
667a9643ea8Slogwang rte_exit(EXIT_FAILURE, "Cannot init clone mbuf pool\n");
668a9643ea8Slogwang
669d30ea906Sjfb8856606 nb_ports = rte_eth_dev_count_avail();
670a9643ea8Slogwang if (nb_ports == 0)
671a9643ea8Slogwang rte_exit(EXIT_FAILURE, "No physical ports!\n");
672a9643ea8Slogwang if (nb_ports > MAX_PORTS)
673a9643ea8Slogwang nb_ports = MAX_PORTS;
674a9643ea8Slogwang
675a9643ea8Slogwang nb_lcores = rte_lcore_count();
676a9643ea8Slogwang
677a9643ea8Slogwang /* initialize all ports */
678d30ea906Sjfb8856606 RTE_ETH_FOREACH_DEV(portid) {
679d30ea906Sjfb8856606 struct rte_eth_rxconf rxq_conf;
680d30ea906Sjfb8856606 struct rte_eth_conf local_port_conf = port_conf;
681d30ea906Sjfb8856606
682a9643ea8Slogwang /* skip ports that are not enabled */
683a9643ea8Slogwang if ((enabled_port_mask & (1 << portid)) == 0) {
684a9643ea8Slogwang printf("Skipping disabled port %d\n", portid);
685a9643ea8Slogwang continue;
686a9643ea8Slogwang }
687a9643ea8Slogwang
688a9643ea8Slogwang qconf = &lcore_queue_conf[rx_lcore_id];
689a9643ea8Slogwang
6902bfe3f2eSlogwang /* limit the frame size to the maximum supported by NIC */
6914418919fSjohnjiang ret = rte_eth_dev_info_get(portid, &dev_info);
6924418919fSjohnjiang if (ret != 0)
6934418919fSjohnjiang rte_exit(EXIT_FAILURE,
6944418919fSjohnjiang "Error during getting device (port %u) info: %s\n",
6954418919fSjohnjiang portid, strerror(-ret));
6964418919fSjohnjiang
697d30ea906Sjfb8856606 local_port_conf.rxmode.max_rx_pkt_len = RTE_MIN(
698d30ea906Sjfb8856606 dev_info.max_rx_pktlen,
699d30ea906Sjfb8856606 local_port_conf.rxmode.max_rx_pkt_len);
7002bfe3f2eSlogwang
701a9643ea8Slogwang /* get the lcore_id for this port */
702a9643ea8Slogwang while (rte_lcore_is_enabled(rx_lcore_id) == 0 ||
703a9643ea8Slogwang qconf->n_rx_queue == (unsigned)rx_queue_per_lcore) {
704a9643ea8Slogwang
705a9643ea8Slogwang rx_lcore_id ++;
706a9643ea8Slogwang qconf = &lcore_queue_conf[rx_lcore_id];
707a9643ea8Slogwang
708a9643ea8Slogwang if (rx_lcore_id >= RTE_MAX_LCORE)
709a9643ea8Slogwang rte_exit(EXIT_FAILURE, "Not enough cores\n");
710a9643ea8Slogwang }
711a9643ea8Slogwang qconf->rx_queue_list[qconf->n_rx_queue] = portid;
712a9643ea8Slogwang qconf->n_rx_queue++;
713a9643ea8Slogwang
714a9643ea8Slogwang /* init port */
715a9643ea8Slogwang printf("Initializing port %d on lcore %u... ", portid,
716a9643ea8Slogwang rx_lcore_id);
717a9643ea8Slogwang fflush(stdout);
718a9643ea8Slogwang
719a9643ea8Slogwang n_tx_queue = nb_lcores;
720a9643ea8Slogwang if (n_tx_queue > MAX_TX_QUEUE_PER_PORT)
721a9643ea8Slogwang n_tx_queue = MAX_TX_QUEUE_PER_PORT;
722d30ea906Sjfb8856606
723a9643ea8Slogwang ret = rte_eth_dev_configure(portid, 1, (uint16_t)n_tx_queue,
724d30ea906Sjfb8856606 &local_port_conf);
725a9643ea8Slogwang if (ret < 0)
726a9643ea8Slogwang rte_exit(EXIT_FAILURE, "Cannot configure device: err=%d, port=%d\n",
727a9643ea8Slogwang ret, portid);
728a9643ea8Slogwang
7292bfe3f2eSlogwang ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd,
7302bfe3f2eSlogwang &nb_txd);
7312bfe3f2eSlogwang if (ret < 0)
7322bfe3f2eSlogwang rte_exit(EXIT_FAILURE,
7332bfe3f2eSlogwang "Cannot adjust number of descriptors: err=%d, port=%d\n",
7342bfe3f2eSlogwang ret, portid);
7352bfe3f2eSlogwang
7364418919fSjohnjiang ret = rte_eth_macaddr_get(portid, &ports_eth_addr[portid]);
7374418919fSjohnjiang if (ret < 0)
7384418919fSjohnjiang rte_exit(EXIT_FAILURE,
7394418919fSjohnjiang "Cannot get MAC address: err=%d, port=%d\n",
7404418919fSjohnjiang ret, portid);
7414418919fSjohnjiang
742a9643ea8Slogwang print_ethaddr(" Address:", &ports_eth_addr[portid]);
743a9643ea8Slogwang printf(", ");
744a9643ea8Slogwang
745a9643ea8Slogwang /* init one RX queue */
746a9643ea8Slogwang queueid = 0;
747a9643ea8Slogwang printf("rxq=%hu ", queueid);
748a9643ea8Slogwang fflush(stdout);
749d30ea906Sjfb8856606 rxq_conf = dev_info.default_rxconf;
750d30ea906Sjfb8856606 rxq_conf.offloads = local_port_conf.rxmode.offloads;
751a9643ea8Slogwang ret = rte_eth_rx_queue_setup(portid, queueid, nb_rxd,
752a9643ea8Slogwang rte_eth_dev_socket_id(portid),
753d30ea906Sjfb8856606 &rxq_conf,
754a9643ea8Slogwang packet_pool);
755a9643ea8Slogwang if (ret < 0)
756a9643ea8Slogwang rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup: err=%d, port=%d\n",
757a9643ea8Slogwang ret, portid);
758a9643ea8Slogwang
759a9643ea8Slogwang /* init one TX queue per couple (lcore,port) */
760a9643ea8Slogwang queueid = 0;
761a9643ea8Slogwang
762a9643ea8Slogwang RTE_LCORE_FOREACH(lcore_id) {
763a9643ea8Slogwang if (rte_lcore_is_enabled(lcore_id) == 0)
764a9643ea8Slogwang continue;
765a9643ea8Slogwang printf("txq=%u,%hu ", lcore_id, queueid);
766a9643ea8Slogwang fflush(stdout);
767a9643ea8Slogwang
768a9643ea8Slogwang txconf = &dev_info.default_txconf;
769d30ea906Sjfb8856606 txconf->offloads = local_port_conf.txmode.offloads;
770a9643ea8Slogwang ret = rte_eth_tx_queue_setup(portid, queueid, nb_txd,
771a9643ea8Slogwang rte_lcore_to_socket_id(lcore_id), txconf);
772a9643ea8Slogwang if (ret < 0)
773a9643ea8Slogwang rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup: err=%d, "
774a9643ea8Slogwang "port=%d\n", ret, portid);
775a9643ea8Slogwang
776a9643ea8Slogwang qconf = &lcore_queue_conf[lcore_id];
777a9643ea8Slogwang qconf->tx_queue_id[portid] = queueid;
778a9643ea8Slogwang queueid++;
779a9643ea8Slogwang }
7804418919fSjohnjiang ret = rte_eth_allmulticast_enable(portid);
7814418919fSjohnjiang if (ret < 0)
7824418919fSjohnjiang rte_exit(EXIT_FAILURE,
7834418919fSjohnjiang "rte_eth_allmulticast_enable: err=%d, port=%d\n",
7844418919fSjohnjiang ret, portid);
785a9643ea8Slogwang /* Start device */
786a9643ea8Slogwang ret = rte_eth_dev_start(portid);
787a9643ea8Slogwang if (ret < 0)
788a9643ea8Slogwang rte_exit(EXIT_FAILURE, "rte_eth_dev_start: err=%d, port=%d\n",
789a9643ea8Slogwang ret, portid);
790a9643ea8Slogwang
791a9643ea8Slogwang printf("done:\n");
792a9643ea8Slogwang }
793a9643ea8Slogwang
794d30ea906Sjfb8856606 check_all_ports_link_status(enabled_port_mask);
795a9643ea8Slogwang
796a9643ea8Slogwang /* initialize the multicast hash */
797a9643ea8Slogwang int retval = init_mcast_hash();
798a9643ea8Slogwang if (retval != 0)
799a9643ea8Slogwang rte_exit(EXIT_FAILURE, "Cannot build the multicast hash\n");
800a9643ea8Slogwang
801a9643ea8Slogwang /* launch per-lcore init on every lcore */
802*2d9fd380Sjfb8856606 rte_eal_mp_remote_launch(main_loop, NULL, CALL_MAIN);
803*2d9fd380Sjfb8856606 RTE_LCORE_FOREACH_WORKER(lcore_id) {
804a9643ea8Slogwang if (rte_eal_wait_lcore(lcore_id) < 0)
805a9643ea8Slogwang return -1;
806a9643ea8Slogwang }
807a9643ea8Slogwang
808a9643ea8Slogwang return 0;
809a9643ea8Slogwang }
810