xref: /dpdk/drivers/net/ngbe/ngbe_rxtx_vec_sse.c (revision 8d75bf037aa29c865ce7ce1c891519ec5118f9df)
1e94c20c3SJiawen Wu /* SPDX-License-Identifier: BSD-3-Clause
2e94c20c3SJiawen Wu  * Copyright(c) 2015-2024 Beijing WangXun Technology Co., Ltd.
3e94c20c3SJiawen Wu  * Copyright(c) 2010-2015 Intel Corporation
4e94c20c3SJiawen Wu  */
5e94c20c3SJiawen Wu 
6e94c20c3SJiawen Wu #include <ethdev_driver.h>
7e94c20c3SJiawen Wu #include <rte_malloc.h>
8e94c20c3SJiawen Wu 
9e94c20c3SJiawen Wu #include "ngbe_type.h"
10e94c20c3SJiawen Wu #include "ngbe_ethdev.h"
11e94c20c3SJiawen Wu #include "ngbe_rxtx.h"
12e94c20c3SJiawen Wu #include "ngbe_rxtx_vec_common.h"
13e94c20c3SJiawen Wu 
14393ff728SBruce Richardson #include <rte_vect.h>
15e94c20c3SJiawen Wu 
16e94c20c3SJiawen Wu static inline void
17e94c20c3SJiawen Wu ngbe_rxq_rearm(struct ngbe_rx_queue *rxq)
18e94c20c3SJiawen Wu {
19e94c20c3SJiawen Wu 	int i;
20e94c20c3SJiawen Wu 	uint16_t rx_id;
21e94c20c3SJiawen Wu 	volatile struct ngbe_rx_desc *rxdp;
22e94c20c3SJiawen Wu 	struct ngbe_rx_entry *rxep = &rxq->sw_ring[rxq->rxrearm_start];
23e94c20c3SJiawen Wu 	struct rte_mbuf *mb0, *mb1;
24e94c20c3SJiawen Wu 	__m128i hdr_room = _mm_set_epi64x(RTE_PKTMBUF_HEADROOM,
25e94c20c3SJiawen Wu 			RTE_PKTMBUF_HEADROOM);
26e94c20c3SJiawen Wu 	__m128i dma_addr0, dma_addr1;
27e94c20c3SJiawen Wu 
28e94c20c3SJiawen Wu 	const __m128i hba_msk = _mm_set_epi64x(0, UINT64_MAX);
29e94c20c3SJiawen Wu 
30e94c20c3SJiawen Wu 	rxdp = rxq->rx_ring + rxq->rxrearm_start;
31e94c20c3SJiawen Wu 
32e94c20c3SJiawen Wu 	/* Pull 'n' more MBUFs into the software ring */
33e94c20c3SJiawen Wu 	if (rte_mempool_get_bulk(rxq->mb_pool,
34e94c20c3SJiawen Wu 				 (void *)rxep,
35e94c20c3SJiawen Wu 				 RTE_NGBE_RXQ_REARM_THRESH) < 0) {
36e94c20c3SJiawen Wu 		if (rxq->rxrearm_nb + RTE_NGBE_RXQ_REARM_THRESH >=
37e94c20c3SJiawen Wu 		    rxq->nb_rx_desc) {
38e94c20c3SJiawen Wu 			dma_addr0 = _mm_setzero_si128();
39e94c20c3SJiawen Wu 			for (i = 0; i < RTE_NGBE_DESCS_PER_LOOP; i++) {
40e94c20c3SJiawen Wu 				rxep[i].mbuf = &rxq->fake_mbuf;
41e94c20c3SJiawen Wu 				_mm_store_si128((__m128i *)(uintptr_t)&rxdp[i],
42e94c20c3SJiawen Wu 						dma_addr0);
43e94c20c3SJiawen Wu 			}
44e94c20c3SJiawen Wu 		}
45e94c20c3SJiawen Wu 		rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed +=
46e94c20c3SJiawen Wu 			RTE_NGBE_RXQ_REARM_THRESH;
47e94c20c3SJiawen Wu 		return;
48e94c20c3SJiawen Wu 	}
49e94c20c3SJiawen Wu 
50e94c20c3SJiawen Wu 	/* Initialize the mbufs in vector, process 2 mbufs in one loop */
51e94c20c3SJiawen Wu 	for (i = 0; i < RTE_NGBE_RXQ_REARM_THRESH; i += 2, rxep += 2) {
52e94c20c3SJiawen Wu 		__m128i vaddr0, vaddr1;
53e94c20c3SJiawen Wu 
54e94c20c3SJiawen Wu 		mb0 = rxep[0].mbuf;
55e94c20c3SJiawen Wu 		mb1 = rxep[1].mbuf;
56e94c20c3SJiawen Wu 
57e94c20c3SJiawen Wu 		/* load buf_addr(lo 64bit) and buf_iova(hi 64bit) */
58e94c20c3SJiawen Wu 		RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, buf_iova) !=
59e94c20c3SJiawen Wu 				offsetof(struct rte_mbuf, buf_addr) + 8);
60e94c20c3SJiawen Wu 		vaddr0 = _mm_loadu_si128((__m128i *)&mb0->buf_addr);
61e94c20c3SJiawen Wu 		vaddr1 = _mm_loadu_si128((__m128i *)&mb1->buf_addr);
62e94c20c3SJiawen Wu 
63e94c20c3SJiawen Wu 		/* convert pa to dma_addr hdr/data */
64e94c20c3SJiawen Wu 		dma_addr0 = _mm_unpackhi_epi64(vaddr0, vaddr0);
65e94c20c3SJiawen Wu 		dma_addr1 = _mm_unpackhi_epi64(vaddr1, vaddr1);
66e94c20c3SJiawen Wu 
67e94c20c3SJiawen Wu 		/* add headroom to pa values */
68e94c20c3SJiawen Wu 		dma_addr0 = _mm_add_epi64(dma_addr0, hdr_room);
69e94c20c3SJiawen Wu 		dma_addr1 = _mm_add_epi64(dma_addr1, hdr_room);
70e94c20c3SJiawen Wu 
71e94c20c3SJiawen Wu 		/* set Header Buffer Address to zero */
72e94c20c3SJiawen Wu 		dma_addr0 =  _mm_and_si128(dma_addr0, hba_msk);
73e94c20c3SJiawen Wu 		dma_addr1 =  _mm_and_si128(dma_addr1, hba_msk);
74e94c20c3SJiawen Wu 
75e94c20c3SJiawen Wu 		/* flush desc with pa dma_addr */
76e94c20c3SJiawen Wu 		_mm_store_si128((__m128i *)(uintptr_t)rxdp++, dma_addr0);
77e94c20c3SJiawen Wu 		_mm_store_si128((__m128i *)(uintptr_t)rxdp++, dma_addr1);
78e94c20c3SJiawen Wu 	}
79e94c20c3SJiawen Wu 
80e94c20c3SJiawen Wu 	rxq->rxrearm_start += RTE_NGBE_RXQ_REARM_THRESH;
81e94c20c3SJiawen Wu 	if (rxq->rxrearm_start >= rxq->nb_rx_desc)
82e94c20c3SJiawen Wu 		rxq->rxrearm_start = 0;
83e94c20c3SJiawen Wu 
84e94c20c3SJiawen Wu 	rxq->rxrearm_nb -= RTE_NGBE_RXQ_REARM_THRESH;
85e94c20c3SJiawen Wu 
86e94c20c3SJiawen Wu 	rx_id = (uint16_t)((rxq->rxrearm_start == 0) ?
87e94c20c3SJiawen Wu 			   (rxq->nb_rx_desc - 1) : (rxq->rxrearm_start - 1));
88e94c20c3SJiawen Wu 
89e94c20c3SJiawen Wu 	/* Update the tail pointer on the NIC */
90e94c20c3SJiawen Wu 	ngbe_set32(rxq->rdt_reg_addr, rx_id);
91e94c20c3SJiawen Wu }
92e94c20c3SJiawen Wu 
93e94c20c3SJiawen Wu static inline void
94e94c20c3SJiawen Wu desc_to_olflags_v(__m128i descs[4], __m128i mbuf_init, uint8_t vlan_flags,
95e94c20c3SJiawen Wu 	struct rte_mbuf **rx_pkts)
96e94c20c3SJiawen Wu {
97e94c20c3SJiawen Wu 	__m128i ptype0, ptype1, vtag0, vtag1, csum, vp;
98e94c20c3SJiawen Wu 	__m128i rearm0, rearm1, rearm2, rearm3;
99e94c20c3SJiawen Wu 
100e94c20c3SJiawen Wu 	/* mask everything except rss type */
101e94c20c3SJiawen Wu 	const __m128i rsstype_msk = _mm_set_epi16(0x0000, 0x0000, 0x0000, 0x0000,
102e94c20c3SJiawen Wu 						  0x000F, 0x000F, 0x000F, 0x000F);
103e94c20c3SJiawen Wu 
104e94c20c3SJiawen Wu 	/* mask the lower byte of ol_flags */
105e94c20c3SJiawen Wu 	const __m128i ol_flags_msk = _mm_set_epi16(0x0000, 0x0000, 0x0000, 0x0000,
106e94c20c3SJiawen Wu 						   0x00FF, 0x00FF, 0x00FF, 0x00FF);
107e94c20c3SJiawen Wu 
108e94c20c3SJiawen Wu 	/* map rss type to rss hash flag */
109e94c20c3SJiawen Wu 	const __m128i rss_flags = _mm_set_epi8(RTE_MBUF_F_RX_FDIR, 0, 0, 0,
110e94c20c3SJiawen Wu 			0, 0, 0, RTE_MBUF_F_RX_RSS_HASH,
111e94c20c3SJiawen Wu 			RTE_MBUF_F_RX_RSS_HASH, 0, RTE_MBUF_F_RX_RSS_HASH, 0,
112e94c20c3SJiawen Wu 			RTE_MBUF_F_RX_RSS_HASH, RTE_MBUF_F_RX_RSS_HASH, RTE_MBUF_F_RX_RSS_HASH, 0);
113e94c20c3SJiawen Wu 
114e94c20c3SJiawen Wu 	/* mask everything except vlan present and l4/ip csum error */
115e94c20c3SJiawen Wu 	const __m128i vlan_csum_msk =
116e94c20c3SJiawen Wu 		_mm_set_epi16((NGBE_RXD_ERR_L4CS | NGBE_RXD_ERR_IPCS) >> 16,
117e94c20c3SJiawen Wu 			      (NGBE_RXD_ERR_L4CS | NGBE_RXD_ERR_IPCS) >> 16,
118e94c20c3SJiawen Wu 			      (NGBE_RXD_ERR_L4CS | NGBE_RXD_ERR_IPCS) >> 16,
119e94c20c3SJiawen Wu 			      (NGBE_RXD_ERR_L4CS | NGBE_RXD_ERR_IPCS) >> 16,
120e94c20c3SJiawen Wu 			      NGBE_RXD_STAT_VLAN, NGBE_RXD_STAT_VLAN,
121e94c20c3SJiawen Wu 			      NGBE_RXD_STAT_VLAN, NGBE_RXD_STAT_VLAN);
122e94c20c3SJiawen Wu 
123e94c20c3SJiawen Wu 	/* map vlan present and l4/ip csum error to ol_flags */
124e94c20c3SJiawen Wu 	const __m128i vlan_csum_map_lo = _mm_set_epi8(0, 0, 0, 0,
125e94c20c3SJiawen Wu 		vlan_flags | RTE_MBUF_F_RX_IP_CKSUM_BAD | RTE_MBUF_F_RX_L4_CKSUM_BAD,
126e94c20c3SJiawen Wu 		vlan_flags | RTE_MBUF_F_RX_IP_CKSUM_BAD,
127e94c20c3SJiawen Wu 		vlan_flags | RTE_MBUF_F_RX_IP_CKSUM_GOOD | RTE_MBUF_F_RX_L4_CKSUM_BAD,
128e94c20c3SJiawen Wu 		vlan_flags | RTE_MBUF_F_RX_IP_CKSUM_GOOD,
129e94c20c3SJiawen Wu 		0, 0, 0, 0,
130e94c20c3SJiawen Wu 		RTE_MBUF_F_RX_IP_CKSUM_BAD | RTE_MBUF_F_RX_L4_CKSUM_BAD,
131e94c20c3SJiawen Wu 		RTE_MBUF_F_RX_IP_CKSUM_BAD,
132e94c20c3SJiawen Wu 		RTE_MBUF_F_RX_IP_CKSUM_GOOD | RTE_MBUF_F_RX_L4_CKSUM_BAD,
133e94c20c3SJiawen Wu 		RTE_MBUF_F_RX_IP_CKSUM_GOOD);
134e94c20c3SJiawen Wu 
135e94c20c3SJiawen Wu 	const __m128i vlan_csum_map_hi = _mm_set_epi8(0, 0, 0, 0,
136e94c20c3SJiawen Wu 		0, RTE_MBUF_F_RX_L4_CKSUM_GOOD >> sizeof(uint8_t), 0,
137e94c20c3SJiawen Wu 		RTE_MBUF_F_RX_L4_CKSUM_GOOD >> sizeof(uint8_t),
138e94c20c3SJiawen Wu 		0, 0, 0, 0,
139e94c20c3SJiawen Wu 		0, RTE_MBUF_F_RX_L4_CKSUM_GOOD >> sizeof(uint8_t), 0,
140e94c20c3SJiawen Wu 		RTE_MBUF_F_RX_L4_CKSUM_GOOD >> sizeof(uint8_t));
141e94c20c3SJiawen Wu 
142e94c20c3SJiawen Wu 	const __m128i vtag_msk = _mm_set_epi16(0x0000, 0x0000, 0x0000, 0x0000,
143e94c20c3SJiawen Wu 					       0x000F, 0x000F, 0x000F, 0x000F);
144e94c20c3SJiawen Wu 
145e94c20c3SJiawen Wu 	ptype0 = _mm_unpacklo_epi16(descs[0], descs[1]);
146e94c20c3SJiawen Wu 	ptype1 = _mm_unpacklo_epi16(descs[2], descs[3]);
147e94c20c3SJiawen Wu 	vtag0 = _mm_unpackhi_epi16(descs[0], descs[1]);
148e94c20c3SJiawen Wu 	vtag1 = _mm_unpackhi_epi16(descs[2], descs[3]);
149e94c20c3SJiawen Wu 
150e94c20c3SJiawen Wu 	ptype0 = _mm_unpacklo_epi32(ptype0, ptype1);
151e94c20c3SJiawen Wu 	ptype0 = _mm_and_si128(ptype0, rsstype_msk);
152e94c20c3SJiawen Wu 	ptype0 = _mm_shuffle_epi8(rss_flags, ptype0);
153e94c20c3SJiawen Wu 
154e94c20c3SJiawen Wu 	vtag1 = _mm_unpacklo_epi32(vtag0, vtag1);
155e94c20c3SJiawen Wu 	vtag1 = _mm_and_si128(vtag1, vlan_csum_msk);
156e94c20c3SJiawen Wu 
157e94c20c3SJiawen Wu 	/* csum bits are in the most significant, to use shuffle we need to
158e94c20c3SJiawen Wu 	 * shift them. Change mask to 0xc000 to 0x0003.
159e94c20c3SJiawen Wu 	 */
160e94c20c3SJiawen Wu 	csum = _mm_srli_epi16(vtag1, 14);
161e94c20c3SJiawen Wu 
162e94c20c3SJiawen Wu 	/* Change mask to 0x20 to 0x08. */
163e94c20c3SJiawen Wu 	vp = _mm_srli_epi16(vtag1, 2);
164e94c20c3SJiawen Wu 
165e94c20c3SJiawen Wu 	/* now or the most significant 64 bits containing the checksum
166e94c20c3SJiawen Wu 	 * flags with the vlan present flags.
167e94c20c3SJiawen Wu 	 */
168e94c20c3SJiawen Wu 	csum = _mm_srli_si128(csum, 8);
169e94c20c3SJiawen Wu 	vtag1 = _mm_or_si128(csum, vtag1);
170e94c20c3SJiawen Wu 	vtag1 = _mm_or_si128(vtag1, vp);
171e94c20c3SJiawen Wu 	vtag1 = _mm_and_si128(vtag1, vtag_msk);
172e94c20c3SJiawen Wu 
173e94c20c3SJiawen Wu 	/* convert STAT_VLAN, ERR_IPCS, ERR_L4CS to ol_flags */
174e94c20c3SJiawen Wu 	vtag0 = _mm_shuffle_epi8(vlan_csum_map_hi, vtag1);
175e94c20c3SJiawen Wu 	vtag0 = _mm_slli_epi16(vtag0, sizeof(uint8_t));
176e94c20c3SJiawen Wu 
177e94c20c3SJiawen Wu 	vtag1 = _mm_shuffle_epi8(vlan_csum_map_lo, vtag1);
178e94c20c3SJiawen Wu 	vtag1 = _mm_and_si128(vtag1, ol_flags_msk);
179e94c20c3SJiawen Wu 	vtag1 = _mm_or_si128(vtag0, vtag1);
180e94c20c3SJiawen Wu 
181e94c20c3SJiawen Wu 	vtag1 = _mm_or_si128(ptype0, vtag1);
182e94c20c3SJiawen Wu 
183e94c20c3SJiawen Wu 	/*
184e94c20c3SJiawen Wu 	 * At this point, we have the 4 sets of flags in the low 64-bits
185e94c20c3SJiawen Wu 	 * of vtag1 (4x16).
186e94c20c3SJiawen Wu 	 * We want to extract these, and merge them with the mbuf init data
187e94c20c3SJiawen Wu 	 * so we can do a single 16-byte write to the mbuf to set the flags
188e94c20c3SJiawen Wu 	 * and all the other initialization fields. Extracting the
189e94c20c3SJiawen Wu 	 * appropriate flags means that we have to do a shift and blend for
190e94c20c3SJiawen Wu 	 * each mbuf before we do the write.
191e94c20c3SJiawen Wu 	 */
192e94c20c3SJiawen Wu 	rearm0 = _mm_blend_epi16(mbuf_init, _mm_slli_si128(vtag1, 8), 0x10);
193e94c20c3SJiawen Wu 	rearm1 = _mm_blend_epi16(mbuf_init, _mm_slli_si128(vtag1, 6), 0x10);
194e94c20c3SJiawen Wu 	rearm2 = _mm_blend_epi16(mbuf_init, _mm_slli_si128(vtag1, 4), 0x10);
195e94c20c3SJiawen Wu 	rearm3 = _mm_blend_epi16(mbuf_init, _mm_slli_si128(vtag1, 2), 0x10);
196e94c20c3SJiawen Wu 
197e94c20c3SJiawen Wu 	/* write the rearm data and the olflags in one write */
198e94c20c3SJiawen Wu 	RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, ol_flags) !=
199e94c20c3SJiawen Wu 			offsetof(struct rte_mbuf, rearm_data) + 8);
200e94c20c3SJiawen Wu 	RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, rearm_data) !=
201e94c20c3SJiawen Wu 			RTE_ALIGN(offsetof(struct rte_mbuf, rearm_data), 16));
202e94c20c3SJiawen Wu 	_mm_store_si128((__m128i *)&rx_pkts[0]->rearm_data, rearm0);
203e94c20c3SJiawen Wu 	_mm_store_si128((__m128i *)&rx_pkts[1]->rearm_data, rearm1);
204e94c20c3SJiawen Wu 	_mm_store_si128((__m128i *)&rx_pkts[2]->rearm_data, rearm2);
205e94c20c3SJiawen Wu 	_mm_store_si128((__m128i *)&rx_pkts[3]->rearm_data, rearm3);
206e94c20c3SJiawen Wu }
207e94c20c3SJiawen Wu 
208e94c20c3SJiawen Wu static inline void
209e94c20c3SJiawen Wu desc_to_ptype_v(__m128i descs[4], uint16_t pkt_type_mask,
210e94c20c3SJiawen Wu 		struct rte_mbuf **rx_pkts)
211e94c20c3SJiawen Wu {
212e94c20c3SJiawen Wu 	__m128i ptype_mask = _mm_set_epi32(pkt_type_mask, pkt_type_mask,
213e94c20c3SJiawen Wu 					pkt_type_mask, pkt_type_mask);
214e94c20c3SJiawen Wu 
215e94c20c3SJiawen Wu 	__m128i ptype0 = _mm_unpacklo_epi32(descs[0], descs[2]);
216e94c20c3SJiawen Wu 	__m128i ptype1 = _mm_unpacklo_epi32(descs[1], descs[3]);
217e94c20c3SJiawen Wu 
218e94c20c3SJiawen Wu 	/* interleave low 32 bits,
219e94c20c3SJiawen Wu 	 * now we have 4 ptypes in a XMM register
220e94c20c3SJiawen Wu 	 */
221e94c20c3SJiawen Wu 	ptype0 = _mm_unpacklo_epi32(ptype0, ptype1);
222e94c20c3SJiawen Wu 
223e94c20c3SJiawen Wu 	/* shift left by NGBE_RXD_PTID_SHIFT, and apply ptype mask */
224e94c20c3SJiawen Wu 	ptype0 = _mm_and_si128(_mm_srli_epi32(ptype0, NGBE_RXD_PTID_SHIFT),
225e94c20c3SJiawen Wu 			       ptype_mask);
226e94c20c3SJiawen Wu 
227e94c20c3SJiawen Wu 	rx_pkts[0]->packet_type = ngbe_decode_ptype(_mm_extract_epi32(ptype0, 0));
228e94c20c3SJiawen Wu 	rx_pkts[1]->packet_type = ngbe_decode_ptype(_mm_extract_epi32(ptype0, 1));
229e94c20c3SJiawen Wu 	rx_pkts[2]->packet_type = ngbe_decode_ptype(_mm_extract_epi32(ptype0, 2));
230e94c20c3SJiawen Wu 	rx_pkts[3]->packet_type = ngbe_decode_ptype(_mm_extract_epi32(ptype0, 3));
231e94c20c3SJiawen Wu }
232e94c20c3SJiawen Wu 
233e94c20c3SJiawen Wu /*
234e94c20c3SJiawen Wu  * vPMD raw receive routine, only accept(nb_pkts >= RTE_NGBE_DESCS_PER_LOOP)
235e94c20c3SJiawen Wu  *
236e94c20c3SJiawen Wu  * Notice:
237e94c20c3SJiawen Wu  * - nb_pkts < RTE_NGBE_DESCS_PER_LOOP, just return no packet
238e94c20c3SJiawen Wu  * - floor align nb_pkts to a RTE_NGBE_DESC_PER_LOOP power-of-two
239e94c20c3SJiawen Wu  */
240e94c20c3SJiawen Wu static inline uint16_t
241e94c20c3SJiawen Wu _recv_raw_pkts_vec(struct ngbe_rx_queue *rxq, struct rte_mbuf **rx_pkts,
242e94c20c3SJiawen Wu 		uint16_t nb_pkts, uint8_t *split_packet)
243e94c20c3SJiawen Wu {
244e94c20c3SJiawen Wu 	volatile struct ngbe_rx_desc *rxdp;
245e94c20c3SJiawen Wu 	struct ngbe_rx_entry *sw_ring;
246e94c20c3SJiawen Wu 	uint16_t nb_pkts_recd;
247e94c20c3SJiawen Wu 	int pos;
248e94c20c3SJiawen Wu 	uint64_t var;
249e94c20c3SJiawen Wu 	__m128i shuf_msk;
250e94c20c3SJiawen Wu 	__m128i crc_adjust = _mm_set_epi16(0, 0, 0, /* ignore non-length fields */
251e94c20c3SJiawen Wu 				-rxq->crc_len, /* sub crc on data_len */
252e94c20c3SJiawen Wu 				0,             /* ignore high-16bits of pkt_len */
253e94c20c3SJiawen Wu 				-rxq->crc_len, /* sub crc on pkt_len */
254e94c20c3SJiawen Wu 				0, 0);         /* ignore pkt_type field */
255e94c20c3SJiawen Wu 
256e94c20c3SJiawen Wu 	/*
257e94c20c3SJiawen Wu 	 * compile-time check the above crc_adjust layout is correct.
258e94c20c3SJiawen Wu 	 * NOTE: the first field (lowest address) is given last in set_epi16
259e94c20c3SJiawen Wu 	 * call above.
260e94c20c3SJiawen Wu 	 */
261e94c20c3SJiawen Wu 	RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, pkt_len) !=
262e94c20c3SJiawen Wu 			offsetof(struct rte_mbuf, rx_descriptor_fields1) + 4);
263e94c20c3SJiawen Wu 	RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, data_len) !=
264e94c20c3SJiawen Wu 			offsetof(struct rte_mbuf, rx_descriptor_fields1) + 8);
265e94c20c3SJiawen Wu 	__m128i dd_check, eop_check;
266e94c20c3SJiawen Wu 	__m128i mbuf_init;
267e94c20c3SJiawen Wu 	uint8_t vlan_flags;
268e94c20c3SJiawen Wu 
269e94c20c3SJiawen Wu 	/*
270e94c20c3SJiawen Wu 	 * Under the circumstance that `rx_tail` wrap back to zero
271e94c20c3SJiawen Wu 	 * and the advance speed of `rx_tail` is greater than `rxrearm_start`,
272e94c20c3SJiawen Wu 	 * `rx_tail` will catch up with `rxrearm_start` and surpass it.
273e94c20c3SJiawen Wu 	 * This may cause some mbufs be reused by application.
274e94c20c3SJiawen Wu 	 *
275e94c20c3SJiawen Wu 	 * So we need to make some restrictions to ensure that
276e94c20c3SJiawen Wu 	 * `rx_tail` will not exceed `rxrearm_start`.
277e94c20c3SJiawen Wu 	 */
278e94c20c3SJiawen Wu 	nb_pkts = RTE_MIN(nb_pkts, RTE_NGBE_RXQ_REARM_THRESH);
279e94c20c3SJiawen Wu 
280e94c20c3SJiawen Wu 	/* nb_pkts has to be floor-aligned to RTE_NGBE_DESCS_PER_LOOP */
281e94c20c3SJiawen Wu 	nb_pkts = RTE_ALIGN_FLOOR(nb_pkts, RTE_NGBE_DESCS_PER_LOOP);
282e94c20c3SJiawen Wu 
283e94c20c3SJiawen Wu 	/* Just the act of getting into the function from the application is
284e94c20c3SJiawen Wu 	 * going to cost about 7 cycles
285e94c20c3SJiawen Wu 	 */
286e94c20c3SJiawen Wu 	rxdp = rxq->rx_ring + rxq->rx_tail;
287e94c20c3SJiawen Wu 
288e94c20c3SJiawen Wu 	rte_prefetch0(rxdp);
289e94c20c3SJiawen Wu 
290e94c20c3SJiawen Wu 	/* See if we need to rearm the RX queue - gives the prefetch a bit
291e94c20c3SJiawen Wu 	 * of time to act
292e94c20c3SJiawen Wu 	 */
293e94c20c3SJiawen Wu 	if (rxq->rxrearm_nb > RTE_NGBE_RXQ_REARM_THRESH)
294e94c20c3SJiawen Wu 		ngbe_rxq_rearm(rxq);
295e94c20c3SJiawen Wu 
296e94c20c3SJiawen Wu 	/* Before we start moving massive data around, check to see if
297e94c20c3SJiawen Wu 	 * there is actually a packet available
298e94c20c3SJiawen Wu 	 */
299e94c20c3SJiawen Wu 	if (!(rxdp->qw1.lo.status &
300e94c20c3SJiawen Wu 				rte_cpu_to_le_32(NGBE_RXD_STAT_DD)))
301e94c20c3SJiawen Wu 		return 0;
302e94c20c3SJiawen Wu 
303e94c20c3SJiawen Wu 	/* 4 packets DD mask */
304e94c20c3SJiawen Wu 	dd_check = _mm_set_epi64x(0x0000000100000001LL, 0x0000000100000001LL);
305e94c20c3SJiawen Wu 
306e94c20c3SJiawen Wu 	/* 4 packets EOP mask */
307e94c20c3SJiawen Wu 	eop_check = _mm_set_epi64x(0x0000000200000002LL, 0x0000000200000002LL);
308e94c20c3SJiawen Wu 
309e94c20c3SJiawen Wu 	/* mask to shuffle from desc. to mbuf */
310e94c20c3SJiawen Wu 	shuf_msk = _mm_set_epi8(7, 6, 5, 4,  /* octet 4~7, 32bits rss */
311e94c20c3SJiawen Wu 		15, 14,      /* octet 14~15, low 16 bits vlan_macip */
312e94c20c3SJiawen Wu 		13, 12,      /* octet 12~13, 16 bits data_len */
313e94c20c3SJiawen Wu 		0xFF, 0xFF,  /* skip high 16 bits pkt_len, zero out */
314e94c20c3SJiawen Wu 		13, 12,      /* octet 12~13, low 16 bits pkt_len */
315e94c20c3SJiawen Wu 		0xFF, 0xFF,  /* skip 32 bit pkt_type */
316e94c20c3SJiawen Wu 		0xFF, 0xFF);
317e94c20c3SJiawen Wu 	/*
318e94c20c3SJiawen Wu 	 * Compile-time verify the shuffle mask
319e94c20c3SJiawen Wu 	 * NOTE: some field positions already verified above, but duplicated
320e94c20c3SJiawen Wu 	 * here for completeness in case of future modifications.
321e94c20c3SJiawen Wu 	 */
322e94c20c3SJiawen Wu 	RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, pkt_len) !=
323e94c20c3SJiawen Wu 			offsetof(struct rte_mbuf, rx_descriptor_fields1) + 4);
324e94c20c3SJiawen Wu 	RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, data_len) !=
325e94c20c3SJiawen Wu 			offsetof(struct rte_mbuf, rx_descriptor_fields1) + 8);
326e94c20c3SJiawen Wu 	RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, vlan_tci) !=
327e94c20c3SJiawen Wu 			offsetof(struct rte_mbuf, rx_descriptor_fields1) + 10);
328e94c20c3SJiawen Wu 	RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, hash) !=
329e94c20c3SJiawen Wu 			offsetof(struct rte_mbuf, rx_descriptor_fields1) + 12);
330e94c20c3SJiawen Wu 
331e94c20c3SJiawen Wu 	mbuf_init = _mm_set_epi64x(0, rxq->mbuf_initializer);
332e94c20c3SJiawen Wu 
333e94c20c3SJiawen Wu 	/* Cache is empty -> need to scan the buffer rings, but first move
334e94c20c3SJiawen Wu 	 * the next 'n' mbufs into the cache
335e94c20c3SJiawen Wu 	 */
336e94c20c3SJiawen Wu 	sw_ring = &rxq->sw_ring[rxq->rx_tail];
337e94c20c3SJiawen Wu 
338e94c20c3SJiawen Wu 	/* ensure these 2 flags are in the lower 8 bits */
339e94c20c3SJiawen Wu 	RTE_BUILD_BUG_ON((RTE_MBUF_F_RX_VLAN | RTE_MBUF_F_RX_VLAN_STRIPPED) > UINT8_MAX);
340e94c20c3SJiawen Wu 	vlan_flags = rxq->vlan_flags & UINT8_MAX;
341e94c20c3SJiawen Wu 
342e94c20c3SJiawen Wu 	/* A. load 4 packet in one loop
343e94c20c3SJiawen Wu 	 * [A*. mask out 4 unused dirty field in desc]
344e94c20c3SJiawen Wu 	 * B. copy 4 mbuf point from swring to rx_pkts
345e94c20c3SJiawen Wu 	 * C. calc the number of DD bits among the 4 packets
346e94c20c3SJiawen Wu 	 * [C*. extract the end-of-packet bit, if requested]
347e94c20c3SJiawen Wu 	 * D. fill info. from desc to mbuf
348e94c20c3SJiawen Wu 	 */
349e94c20c3SJiawen Wu 	for (pos = 0, nb_pkts_recd = 0; pos < nb_pkts;
350e94c20c3SJiawen Wu 			pos += RTE_NGBE_DESCS_PER_LOOP,
351e94c20c3SJiawen Wu 			rxdp += RTE_NGBE_DESCS_PER_LOOP) {
352e94c20c3SJiawen Wu 		__m128i descs[RTE_NGBE_DESCS_PER_LOOP];
353e94c20c3SJiawen Wu 		__m128i pkt_mb1, pkt_mb2, pkt_mb3, pkt_mb4;
354e94c20c3SJiawen Wu 		__m128i zero, staterr, sterr_tmp1, sterr_tmp2;
355e94c20c3SJiawen Wu 		/* 2 64 bit or 4 32 bit mbuf pointers in one XMM reg. */
356e94c20c3SJiawen Wu 		__m128i mbp1;
357e94c20c3SJiawen Wu #if defined(RTE_ARCH_X86_64)
358e94c20c3SJiawen Wu 		__m128i mbp2;
359e94c20c3SJiawen Wu #endif
360e94c20c3SJiawen Wu 
361e94c20c3SJiawen Wu 		/* B.1 load 2 (64 bit) or 4 (32 bit) mbuf points */
362e94c20c3SJiawen Wu 		mbp1 = _mm_loadu_si128((__m128i *)&sw_ring[pos]);
363e94c20c3SJiawen Wu 
364e94c20c3SJiawen Wu 		/* Read desc statuses backwards to avoid race condition */
365e94c20c3SJiawen Wu 		/* A.1 load desc[3] */
366e94c20c3SJiawen Wu 		descs[3] = _mm_loadu_si128((__m128i *)(uintptr_t)(rxdp + 3));
367e94c20c3SJiawen Wu 		rte_compiler_barrier();
368e94c20c3SJiawen Wu 
369e94c20c3SJiawen Wu 		/* B.2 copy 2 64 bit or 4 32 bit mbuf point into rx_pkts */
370e94c20c3SJiawen Wu 		_mm_storeu_si128((__m128i *)&rx_pkts[pos], mbp1);
371e94c20c3SJiawen Wu 
372e94c20c3SJiawen Wu #if defined(RTE_ARCH_X86_64)
373e94c20c3SJiawen Wu 		/* B.1 load 2 64 bit mbuf points */
374e94c20c3SJiawen Wu 		mbp2 = _mm_loadu_si128((__m128i *)&sw_ring[pos + 2]);
375e94c20c3SJiawen Wu #endif
376e94c20c3SJiawen Wu 
377e94c20c3SJiawen Wu 		/* A.1 load desc[2-0] */
378e94c20c3SJiawen Wu 		descs[2] = _mm_loadu_si128((__m128i *)(uintptr_t)(rxdp + 2));
379e94c20c3SJiawen Wu 		rte_compiler_barrier();
380e94c20c3SJiawen Wu 		descs[1] = _mm_loadu_si128((__m128i *)(uintptr_t)(rxdp + 1));
381e94c20c3SJiawen Wu 		rte_compiler_barrier();
382e94c20c3SJiawen Wu 		descs[0] = _mm_loadu_si128((__m128i *)(uintptr_t)(rxdp));
383e94c20c3SJiawen Wu 
384e94c20c3SJiawen Wu #if defined(RTE_ARCH_X86_64)
385e94c20c3SJiawen Wu 		/* B.2 copy 2 mbuf point into rx_pkts  */
386e94c20c3SJiawen Wu 		_mm_storeu_si128((__m128i *)&rx_pkts[pos + 2], mbp2);
387e94c20c3SJiawen Wu #endif
388e94c20c3SJiawen Wu 
389e94c20c3SJiawen Wu 		if (split_packet) {
390e94c20c3SJiawen Wu 			rte_mbuf_prefetch_part2(rx_pkts[pos]);
391e94c20c3SJiawen Wu 			rte_mbuf_prefetch_part2(rx_pkts[pos + 1]);
392e94c20c3SJiawen Wu 			rte_mbuf_prefetch_part2(rx_pkts[pos + 2]);
393e94c20c3SJiawen Wu 			rte_mbuf_prefetch_part2(rx_pkts[pos + 3]);
394e94c20c3SJiawen Wu 		}
395e94c20c3SJiawen Wu 
396e94c20c3SJiawen Wu 		/* avoid compiler reorder optimization */
397e94c20c3SJiawen Wu 		rte_compiler_barrier();
398e94c20c3SJiawen Wu 
399e94c20c3SJiawen Wu 		/* D.1 pkt 3,4 convert format from desc to pktmbuf */
400e94c20c3SJiawen Wu 		pkt_mb4 = _mm_shuffle_epi8(descs[3], shuf_msk);
401e94c20c3SJiawen Wu 		pkt_mb3 = _mm_shuffle_epi8(descs[2], shuf_msk);
402e94c20c3SJiawen Wu 
403e94c20c3SJiawen Wu 		/* D.1 pkt 1,2 convert format from desc to pktmbuf */
404e94c20c3SJiawen Wu 		pkt_mb2 = _mm_shuffle_epi8(descs[1], shuf_msk);
405e94c20c3SJiawen Wu 		pkt_mb1 = _mm_shuffle_epi8(descs[0], shuf_msk);
406e94c20c3SJiawen Wu 
407e94c20c3SJiawen Wu 		/* C.1 4=>2 filter staterr info only */
408e94c20c3SJiawen Wu 		sterr_tmp2 = _mm_unpackhi_epi32(descs[3], descs[2]);
409e94c20c3SJiawen Wu 		/* C.1 4=>2 filter staterr info only */
410e94c20c3SJiawen Wu 		sterr_tmp1 = _mm_unpackhi_epi32(descs[1], descs[0]);
411e94c20c3SJiawen Wu 
412e94c20c3SJiawen Wu 		/* set ol_flags with vlan packet type */
413e94c20c3SJiawen Wu 		desc_to_olflags_v(descs, mbuf_init, vlan_flags, &rx_pkts[pos]);
414e94c20c3SJiawen Wu 
415e94c20c3SJiawen Wu 		/* D.2 pkt 3,4 set in_port/nb_seg and remove crc */
416e94c20c3SJiawen Wu 		pkt_mb4 = _mm_add_epi16(pkt_mb4, crc_adjust);
417e94c20c3SJiawen Wu 		pkt_mb3 = _mm_add_epi16(pkt_mb3, crc_adjust);
418e94c20c3SJiawen Wu 
419e94c20c3SJiawen Wu 		/* C.2 get 4 pkts staterr value  */
420e94c20c3SJiawen Wu 		zero = _mm_xor_si128(dd_check, dd_check);
421e94c20c3SJiawen Wu 		staterr = _mm_unpacklo_epi32(sterr_tmp1, sterr_tmp2);
422e94c20c3SJiawen Wu 
423e94c20c3SJiawen Wu 		/* D.3 copy final 3,4 data to rx_pkts */
424e94c20c3SJiawen Wu 		_mm_storeu_si128((void *)&rx_pkts[pos + 3]->rx_descriptor_fields1,
425e94c20c3SJiawen Wu 				pkt_mb4);
426e94c20c3SJiawen Wu 		_mm_storeu_si128((void *)&rx_pkts[pos + 2]->rx_descriptor_fields1,
427e94c20c3SJiawen Wu 				pkt_mb3);
428e94c20c3SJiawen Wu 
429e94c20c3SJiawen Wu 		/* D.2 pkt 1,2 set in_port/nb_seg and remove crc */
430e94c20c3SJiawen Wu 		pkt_mb2 = _mm_add_epi16(pkt_mb2, crc_adjust);
431e94c20c3SJiawen Wu 		pkt_mb1 = _mm_add_epi16(pkt_mb1, crc_adjust);
432e94c20c3SJiawen Wu 
433e94c20c3SJiawen Wu 		/* C* extract and record EOP bit */
434e94c20c3SJiawen Wu 		if (split_packet) {
435e94c20c3SJiawen Wu 			__m128i eop_shuf_mask =
436e94c20c3SJiawen Wu 				_mm_set_epi8(0xFF, 0xFF, 0xFF, 0xFF,
437e94c20c3SJiawen Wu 					     0xFF, 0xFF, 0xFF, 0xFF,
438e94c20c3SJiawen Wu 					     0xFF, 0xFF, 0xFF, 0xFF,
439e94c20c3SJiawen Wu 					     0x04, 0x0C, 0x00, 0x08);
440e94c20c3SJiawen Wu 
441e94c20c3SJiawen Wu 			/* and with mask to extract bits, flipping 1-0 */
442e94c20c3SJiawen Wu 			__m128i eop_bits = _mm_andnot_si128(staterr, eop_check);
443e94c20c3SJiawen Wu 			/* the staterr values are not in order, as the count
444e94c20c3SJiawen Wu 			 * of dd bits doesn't care. However, for end of
445e94c20c3SJiawen Wu 			 * packet tracking, we do care, so shuffle. This also
446e94c20c3SJiawen Wu 			 * compresses the 32-bit values to 8-bit
447e94c20c3SJiawen Wu 			 */
448e94c20c3SJiawen Wu 			eop_bits = _mm_shuffle_epi8(eop_bits, eop_shuf_mask);
449e94c20c3SJiawen Wu 			/* store the resulting 32-bit value */
450e94c20c3SJiawen Wu 			*(int *)split_packet = _mm_cvtsi128_si32(eop_bits);
451e94c20c3SJiawen Wu 			split_packet += RTE_NGBE_DESCS_PER_LOOP;
452e94c20c3SJiawen Wu 		}
453e94c20c3SJiawen Wu 
454e94c20c3SJiawen Wu 		/* C.3 calc available number of desc */
455e94c20c3SJiawen Wu 		staterr = _mm_and_si128(staterr, dd_check);
456e94c20c3SJiawen Wu 		staterr = _mm_packs_epi32(staterr, zero);
457e94c20c3SJiawen Wu 
458e94c20c3SJiawen Wu 		/* D.3 copy final 1,2 data to rx_pkts */
459e94c20c3SJiawen Wu 		_mm_storeu_si128((void *)&rx_pkts[pos + 1]->rx_descriptor_fields1,
460e94c20c3SJiawen Wu 				pkt_mb2);
461e94c20c3SJiawen Wu 		_mm_storeu_si128((void *)&rx_pkts[pos]->rx_descriptor_fields1,
462e94c20c3SJiawen Wu 				pkt_mb1);
463e94c20c3SJiawen Wu 
464e94c20c3SJiawen Wu 		desc_to_ptype_v(descs, NGBE_PTID_MASK, &rx_pkts[pos]);
465e94c20c3SJiawen Wu 
466e94c20c3SJiawen Wu 		/* C.4 calc available number of desc */
467e94c20c3SJiawen Wu 		var = rte_popcount64(_mm_cvtsi128_si64(staterr));
468e94c20c3SJiawen Wu 		nb_pkts_recd += var;
469e94c20c3SJiawen Wu 		if (likely(var != RTE_NGBE_DESCS_PER_LOOP))
470e94c20c3SJiawen Wu 			break;
471e94c20c3SJiawen Wu 	}
472e94c20c3SJiawen Wu 
473e94c20c3SJiawen Wu 	/* Update our internal tail pointer */
474e94c20c3SJiawen Wu 	rxq->rx_tail = (uint16_t)(rxq->rx_tail + nb_pkts_recd);
475e94c20c3SJiawen Wu 	rxq->rx_tail = (uint16_t)(rxq->rx_tail & (rxq->nb_rx_desc - 1));
476e94c20c3SJiawen Wu 	rxq->rxrearm_nb = (uint16_t)(rxq->rxrearm_nb + nb_pkts_recd);
477e94c20c3SJiawen Wu 
478e94c20c3SJiawen Wu 	return nb_pkts_recd;
479e94c20c3SJiawen Wu }
480e94c20c3SJiawen Wu 
481e94c20c3SJiawen Wu /*
482e94c20c3SJiawen Wu  * vPMD receive routine, only accept(nb_pkts >= RTE_NGBE_DESCS_PER_LOOP)
483e94c20c3SJiawen Wu  *
484e94c20c3SJiawen Wu  * Notice:
485e94c20c3SJiawen Wu  * - nb_pkts < RTE_NGBE_DESCS_PER_LOOP, just return no packet
486e94c20c3SJiawen Wu  * - floor align nb_pkts to a RTE_NGBE_DESC_PER_LOOP power-of-two
487e94c20c3SJiawen Wu  */
488e94c20c3SJiawen Wu uint16_t
489e94c20c3SJiawen Wu ngbe_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
490e94c20c3SJiawen Wu 		uint16_t nb_pkts)
491e94c20c3SJiawen Wu {
492e94c20c3SJiawen Wu 	return _recv_raw_pkts_vec(rx_queue, rx_pkts, nb_pkts, NULL);
493e94c20c3SJiawen Wu }
494e94c20c3SJiawen Wu 
495e94c20c3SJiawen Wu /**
496e94c20c3SJiawen Wu  * vPMD receive routine that reassembles scattered packets
497e94c20c3SJiawen Wu  *
498e94c20c3SJiawen Wu  * Notice:
499e94c20c3SJiawen Wu  * - nb_pkts < RTE_NGBE_DESCS_PER_LOOP, just return no packet
500e94c20c3SJiawen Wu  * - floor align nb_pkts to a RTE_NGBE_DESC_PER_LOOP power-of-two
501e94c20c3SJiawen Wu  */
502e94c20c3SJiawen Wu static uint16_t
503e94c20c3SJiawen Wu ngbe_recv_scattered_burst_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
504e94c20c3SJiawen Wu 			       uint16_t nb_pkts)
505e94c20c3SJiawen Wu {
506e94c20c3SJiawen Wu 	struct ngbe_rx_queue *rxq = rx_queue;
507e94c20c3SJiawen Wu 	uint8_t split_flags[RTE_NGBE_MAX_RX_BURST] = {0};
508e94c20c3SJiawen Wu 
509e94c20c3SJiawen Wu 	/* get some new buffers */
510e94c20c3SJiawen Wu 	uint16_t nb_bufs = _recv_raw_pkts_vec(rxq, rx_pkts, nb_pkts,
511e94c20c3SJiawen Wu 			split_flags);
512e94c20c3SJiawen Wu 	if (nb_bufs == 0)
513e94c20c3SJiawen Wu 		return 0;
514e94c20c3SJiawen Wu 
515e94c20c3SJiawen Wu 	/* happy day case, full burst + no packets to be joined */
516e94c20c3SJiawen Wu 	const uint64_t *split_fl64 = (uint64_t *)split_flags;
517e94c20c3SJiawen Wu 	if (rxq->pkt_first_seg == NULL &&
518e94c20c3SJiawen Wu 			split_fl64[0] == 0 && split_fl64[1] == 0 &&
519e94c20c3SJiawen Wu 			split_fl64[2] == 0 && split_fl64[3] == 0)
520e94c20c3SJiawen Wu 		return nb_bufs;
521e94c20c3SJiawen Wu 
522e94c20c3SJiawen Wu 	/* reassemble any packets that need reassembly*/
523e94c20c3SJiawen Wu 	unsigned int i = 0;
524e94c20c3SJiawen Wu 	if (rxq->pkt_first_seg == NULL) {
525e94c20c3SJiawen Wu 		/* find the first split flag, and only reassemble then*/
526e94c20c3SJiawen Wu 		while (i < nb_bufs && !split_flags[i])
527e94c20c3SJiawen Wu 			i++;
528e94c20c3SJiawen Wu 		if (i == nb_bufs)
529e94c20c3SJiawen Wu 			return nb_bufs;
530e94c20c3SJiawen Wu 		rxq->pkt_first_seg = rx_pkts[i];
531e94c20c3SJiawen Wu 	}
532e94c20c3SJiawen Wu 	return i + reassemble_packets(rxq, &rx_pkts[i], nb_bufs - i,
533e94c20c3SJiawen Wu 		&split_flags[i]);
534e94c20c3SJiawen Wu }
535e94c20c3SJiawen Wu 
536e94c20c3SJiawen Wu /**
537e94c20c3SJiawen Wu  * vPMD receive routine that reassembles scattered packets.
538e94c20c3SJiawen Wu  */
539e94c20c3SJiawen Wu uint16_t
540e94c20c3SJiawen Wu ngbe_recv_scattered_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
541e94c20c3SJiawen Wu 			     uint16_t nb_pkts)
542e94c20c3SJiawen Wu {
543e94c20c3SJiawen Wu 	uint16_t retval = 0;
544e94c20c3SJiawen Wu 
545e94c20c3SJiawen Wu 	while (nb_pkts > RTE_NGBE_MAX_RX_BURST) {
546e94c20c3SJiawen Wu 		uint16_t burst;
547e94c20c3SJiawen Wu 
548e94c20c3SJiawen Wu 		burst = ngbe_recv_scattered_burst_vec(rx_queue,
549e94c20c3SJiawen Wu 						      rx_pkts + retval,
550e94c20c3SJiawen Wu 						      RTE_NGBE_MAX_RX_BURST);
551e94c20c3SJiawen Wu 		retval += burst;
552e94c20c3SJiawen Wu 		nb_pkts -= burst;
553e94c20c3SJiawen Wu 		if (burst < RTE_NGBE_MAX_RX_BURST)
554e94c20c3SJiawen Wu 			return retval;
555e94c20c3SJiawen Wu 	}
556e94c20c3SJiawen Wu 
557e94c20c3SJiawen Wu 	return retval + ngbe_recv_scattered_burst_vec(rx_queue,
558e94c20c3SJiawen Wu 						      rx_pkts + retval,
559e94c20c3SJiawen Wu 						      nb_pkts);
560e94c20c3SJiawen Wu }
561e94c20c3SJiawen Wu 
562e94c20c3SJiawen Wu static inline void
563e94c20c3SJiawen Wu vtx1(volatile struct ngbe_tx_desc *txdp,
564e94c20c3SJiawen Wu 		struct rte_mbuf *pkt, uint64_t flags)
565e94c20c3SJiawen Wu {
566*8d75bf03SJiawen Wu 	uint16_t pkt_len = pkt->data_len;
567*8d75bf03SJiawen Wu 	__m128i descriptor;
568*8d75bf03SJiawen Wu 
569*8d75bf03SJiawen Wu 	if (pkt_len < RTE_ETHER_HDR_LEN)
570*8d75bf03SJiawen Wu 		pkt_len = NGBE_FRAME_SIZE_DFT;
571*8d75bf03SJiawen Wu 
572*8d75bf03SJiawen Wu 	descriptor = _mm_set_epi64x((uint64_t)pkt_len << 45 | flags | pkt_len,
573e94c20c3SJiawen Wu 				pkt->buf_iova + pkt->data_off);
574e94c20c3SJiawen Wu 	_mm_store_si128((__m128i *)(uintptr_t)txdp, descriptor);
575e94c20c3SJiawen Wu }
576e94c20c3SJiawen Wu 
577e94c20c3SJiawen Wu static inline void
578e94c20c3SJiawen Wu vtx(volatile struct ngbe_tx_desc *txdp,
579e94c20c3SJiawen Wu 		struct rte_mbuf **pkt, uint16_t nb_pkts,  uint64_t flags)
580e94c20c3SJiawen Wu {
581e94c20c3SJiawen Wu 	int i;
582e94c20c3SJiawen Wu 
583e94c20c3SJiawen Wu 	for (i = 0; i < nb_pkts; ++i, ++txdp, ++pkt)
584e94c20c3SJiawen Wu 		vtx1(txdp, *pkt, flags);
585e94c20c3SJiawen Wu }
586e94c20c3SJiawen Wu 
587e94c20c3SJiawen Wu uint16_t
588e94c20c3SJiawen Wu ngbe_xmit_fixed_burst_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
589e94c20c3SJiawen Wu 			  uint16_t nb_pkts)
590e94c20c3SJiawen Wu {
591e94c20c3SJiawen Wu 	struct ngbe_tx_queue *txq = (struct ngbe_tx_queue *)tx_queue;
592e94c20c3SJiawen Wu 	volatile struct ngbe_tx_desc *txdp;
593e94c20c3SJiawen Wu 	struct ngbe_tx_entry_v *txep;
594e94c20c3SJiawen Wu 	uint16_t n, nb_commit, tx_id;
595e94c20c3SJiawen Wu 	uint64_t flags = NGBE_TXD_FLAGS;
596e94c20c3SJiawen Wu 	uint64_t rs = NGBE_TXD_FLAGS;
597e94c20c3SJiawen Wu 	int i;
598e94c20c3SJiawen Wu 
599e94c20c3SJiawen Wu 	/* cross rx_thresh boundary is not allowed */
600e94c20c3SJiawen Wu 	nb_pkts = RTE_MIN(nb_pkts, txq->tx_free_thresh);
601e94c20c3SJiawen Wu 
602e94c20c3SJiawen Wu 	if (txq->nb_tx_free < txq->tx_free_thresh)
603e94c20c3SJiawen Wu 		ngbe_tx_free_bufs(txq);
604e94c20c3SJiawen Wu 
605e94c20c3SJiawen Wu 	nb_pkts = (uint16_t)RTE_MIN(txq->nb_tx_free, nb_pkts);
606e94c20c3SJiawen Wu 	if (unlikely(nb_pkts == 0))
607e94c20c3SJiawen Wu 		return 0;
608e94c20c3SJiawen Wu 
609e94c20c3SJiawen Wu 	tx_id = txq->tx_tail;
610e94c20c3SJiawen Wu 	txdp = &txq->tx_ring[tx_id];
611e94c20c3SJiawen Wu 	txep = &txq->sw_ring_v[tx_id];
612e94c20c3SJiawen Wu 
613e94c20c3SJiawen Wu 	txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_pkts);
614e94c20c3SJiawen Wu 
615e94c20c3SJiawen Wu 	n = (uint16_t)(txq->nb_tx_desc - tx_id);
616e94c20c3SJiawen Wu 	nb_commit = nb_pkts;
617e94c20c3SJiawen Wu 	if (nb_commit >= n) {
618e94c20c3SJiawen Wu 		tx_backlog_entry(txep, tx_pkts, n);
619e94c20c3SJiawen Wu 
620e94c20c3SJiawen Wu 		for (i = 0; i < n - 1; ++i, ++tx_pkts, ++txdp)
621e94c20c3SJiawen Wu 			vtx1(txdp, *tx_pkts, flags);
622e94c20c3SJiawen Wu 
623e94c20c3SJiawen Wu 		vtx1(txdp, *tx_pkts++, rs);
624e94c20c3SJiawen Wu 
625e94c20c3SJiawen Wu 		nb_commit = (uint16_t)(nb_commit - n);
626e94c20c3SJiawen Wu 
627e94c20c3SJiawen Wu 		tx_id = 0;
628e94c20c3SJiawen Wu 
629e94c20c3SJiawen Wu 		/* avoid reach the end of ring */
630e94c20c3SJiawen Wu 		txdp = &txq->tx_ring[tx_id];
631e94c20c3SJiawen Wu 		txep = &txq->sw_ring_v[tx_id];
632e94c20c3SJiawen Wu 	}
633e94c20c3SJiawen Wu 
634e94c20c3SJiawen Wu 	tx_backlog_entry(txep, tx_pkts, nb_commit);
635e94c20c3SJiawen Wu 
636e94c20c3SJiawen Wu 	vtx(txdp, tx_pkts, nb_commit, flags);
637e94c20c3SJiawen Wu 
638e94c20c3SJiawen Wu 	tx_id = (uint16_t)(tx_id + nb_commit);
639e94c20c3SJiawen Wu 
640e94c20c3SJiawen Wu 	txq->tx_tail = tx_id;
641e94c20c3SJiawen Wu 
642e94c20c3SJiawen Wu 	ngbe_set32(txq->tdt_reg_addr, txq->tx_tail);
643e94c20c3SJiawen Wu 
644e94c20c3SJiawen Wu 	return nb_pkts;
645e94c20c3SJiawen Wu }
646e94c20c3SJiawen Wu 
647e94c20c3SJiawen Wu static void __rte_cold
648e94c20c3SJiawen Wu ngbe_tx_queue_release_mbufs_vec(struct ngbe_tx_queue *txq)
649e94c20c3SJiawen Wu {
650e94c20c3SJiawen Wu 	_ngbe_tx_queue_release_mbufs_vec(txq);
651e94c20c3SJiawen Wu }
652e94c20c3SJiawen Wu 
653e94c20c3SJiawen Wu void __rte_cold
654e94c20c3SJiawen Wu ngbe_rx_queue_release_mbufs_vec(struct ngbe_rx_queue *rxq)
655e94c20c3SJiawen Wu {
656e94c20c3SJiawen Wu 	_ngbe_rx_queue_release_mbufs_vec(rxq);
657e94c20c3SJiawen Wu }
658e94c20c3SJiawen Wu 
659e94c20c3SJiawen Wu static void __rte_cold
660e94c20c3SJiawen Wu ngbe_tx_free_swring(struct ngbe_tx_queue *txq)
661e94c20c3SJiawen Wu {
662e94c20c3SJiawen Wu 	_ngbe_tx_free_swring_vec(txq);
663e94c20c3SJiawen Wu }
664e94c20c3SJiawen Wu 
665e94c20c3SJiawen Wu static void __rte_cold
666e94c20c3SJiawen Wu ngbe_reset_tx_queue(struct ngbe_tx_queue *txq)
667e94c20c3SJiawen Wu {
668e94c20c3SJiawen Wu 	_ngbe_reset_tx_queue_vec(txq);
669e94c20c3SJiawen Wu }
670e94c20c3SJiawen Wu 
671e94c20c3SJiawen Wu static const struct ngbe_txq_ops vec_txq_ops = {
672e94c20c3SJiawen Wu 	.release_mbufs = ngbe_tx_queue_release_mbufs_vec,
673e94c20c3SJiawen Wu 	.free_swring = ngbe_tx_free_swring,
674e94c20c3SJiawen Wu 	.reset = ngbe_reset_tx_queue,
675e94c20c3SJiawen Wu };
676e94c20c3SJiawen Wu 
677e94c20c3SJiawen Wu int __rte_cold
678e94c20c3SJiawen Wu ngbe_rxq_vec_setup(struct ngbe_rx_queue *rxq)
679e94c20c3SJiawen Wu {
680e94c20c3SJiawen Wu 	return ngbe_rxq_vec_setup_default(rxq);
681e94c20c3SJiawen Wu }
682e94c20c3SJiawen Wu 
683e94c20c3SJiawen Wu int __rte_cold
684e94c20c3SJiawen Wu ngbe_txq_vec_setup(struct ngbe_tx_queue *txq)
685e94c20c3SJiawen Wu {
686e94c20c3SJiawen Wu 	return ngbe_txq_vec_setup_default(txq, &vec_txq_ops);
687e94c20c3SJiawen Wu }
688e94c20c3SJiawen Wu 
689e94c20c3SJiawen Wu int __rte_cold
690e94c20c3SJiawen Wu ngbe_rx_vec_dev_conf_condition_check(struct rte_eth_dev *dev)
691e94c20c3SJiawen Wu {
692e94c20c3SJiawen Wu 	return ngbe_rx_vec_dev_conf_condition_check_default(dev);
693e94c20c3SJiawen Wu }
694