4 * Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <rte_ethdev.h>
36 #include <rte_malloc.h>
38 #include "ixgbe_ethdev.h"
39 #include "ixgbe_rxtx.h"
41 #include <tmmintrin.h>
43 #ifndef __INTEL_COMPILER
44 #pragma GCC diagnostic ignored "-Wcast-qual"
48 ixgbe_rxq_rearm(struct ixgbe_rx_queue *rxq)
52 volatile union ixgbe_adv_rx_desc *rxdp;
53 struct ixgbe_rx_entry *rxep = &rxq->sw_ring[rxq->rxrearm_start];
54 struct rte_mbuf *mb0, *mb1;
55 __m128i hdr_room = _mm_set_epi64x(RTE_PKTMBUF_HEADROOM,
56 RTE_PKTMBUF_HEADROOM);
57 __m128i dma_addr0, dma_addr1;
59 const __m128i hba_msk = _mm_set_epi64x(0, UINT64_MAX);
61 rxdp = rxq->rx_ring + rxq->rxrearm_start;
63 /* Pull 'n' more MBUFs into the software ring */
64 if (rte_mempool_get_bulk(rxq->mb_pool,
66 RTE_IXGBE_RXQ_REARM_THRESH) < 0) {
67 if (rxq->rxrearm_nb + RTE_IXGBE_RXQ_REARM_THRESH >=
69 dma_addr0 = _mm_setzero_si128();
70 for (i = 0; i < RTE_IXGBE_DESCS_PER_LOOP; i++) {
71 rxep[i].mbuf = &rxq->fake_mbuf;
72 _mm_store_si128((__m128i *)&rxdp[i].read,
76 rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed +=
77 RTE_IXGBE_RXQ_REARM_THRESH;
81 /* Initialize the mbufs in vector, process 2 mbufs in one loop */
82 for (i = 0; i < RTE_IXGBE_RXQ_REARM_THRESH; i += 2, rxep += 2) {
83 __m128i vaddr0, vaddr1;
90 * Flush mbuf with pkt template.
91 * Data to be rearmed is 6 bytes long.
92 * Though, RX will overwrite ol_flags that are coming next
93 * anyway. So overwrite whole 8 bytes with one load:
94 * 6 bytes of rearm_data plus first 2 bytes of ol_flags.
96 p0 = (uintptr_t)&mb0->rearm_data;
97 *(uint64_t *)p0 = rxq->mbuf_initializer;
98 p1 = (uintptr_t)&mb1->rearm_data;
99 *(uint64_t *)p1 = rxq->mbuf_initializer;
101 /* load buf_addr(lo 64bit) and buf_physaddr(hi 64bit) */
102 vaddr0 = _mm_loadu_si128((__m128i *)&(mb0->buf_addr));
103 vaddr1 = _mm_loadu_si128((__m128i *)&(mb1->buf_addr));
105 /* convert pa to dma_addr hdr/data */
106 dma_addr0 = _mm_unpackhi_epi64(vaddr0, vaddr0);
107 dma_addr1 = _mm_unpackhi_epi64(vaddr1, vaddr1);
109 /* add headroom to pa values */
110 dma_addr0 = _mm_add_epi64(dma_addr0, hdr_room);
111 dma_addr1 = _mm_add_epi64(dma_addr1, hdr_room);
113 /* set Header Buffer Address to zero */
114 dma_addr0 = _mm_and_si128(dma_addr0, hba_msk);
115 dma_addr1 = _mm_and_si128(dma_addr1, hba_msk);
117 /* flush desc with pa dma_addr */
118 _mm_store_si128((__m128i *)&rxdp++->read, dma_addr0);
119 _mm_store_si128((__m128i *)&rxdp++->read, dma_addr1);
122 rxq->rxrearm_start += RTE_IXGBE_RXQ_REARM_THRESH;
123 if (rxq->rxrearm_start >= rxq->nb_rx_desc)
124 rxq->rxrearm_start = 0;
126 rxq->rxrearm_nb -= RTE_IXGBE_RXQ_REARM_THRESH;
128 rx_id = (uint16_t) ((rxq->rxrearm_start == 0) ?
129 (rxq->nb_rx_desc - 1) : (rxq->rxrearm_start - 1));
131 /* Update the tail pointer on the NIC */
132 IXGBE_PCI_REG_WRITE(rxq->rdt_reg_addr, rx_id);
135 /* Handling the offload flags (olflags) field takes computation
136 * time when receiving packets. Therefore we provide a flag to disable
137 * the processing of the olflags field when they are not needed. This
138 * gives improved performance, at the cost of losing the offload info
139 * in the received packet
141 #ifdef RTE_IXGBE_RX_OLFLAGS_ENABLE
143 #define VTAG_SHIFT (3)
146 desc_to_olflags_v(__m128i descs[4], struct rte_mbuf **rx_pkts)
148 __m128i ptype0, ptype1, vtag0, vtag1;
154 /* pkt type + vlan olflags mask */
155 const __m128i pkttype_msk = _mm_set_epi16(
156 0x0000, 0x0000, 0x0000, 0x0000,
157 PKT_RX_VLAN_PKT, PKT_RX_VLAN_PKT, PKT_RX_VLAN_PKT, PKT_RX_VLAN_PKT);
159 /* mask everything except rss type */
160 const __m128i rsstype_msk = _mm_set_epi16(
161 0x0000, 0x0000, 0x0000, 0x0000,
162 0x000F, 0x000F, 0x000F, 0x000F);
164 /* map rss type to rss hash flag */
165 const __m128i rss_flags = _mm_set_epi8(PKT_RX_FDIR, 0, 0, 0,
166 0, 0, 0, PKT_RX_RSS_HASH,
167 PKT_RX_RSS_HASH, 0, PKT_RX_RSS_HASH, 0,
168 PKT_RX_RSS_HASH, PKT_RX_RSS_HASH, PKT_RX_RSS_HASH, 0);
170 ptype0 = _mm_unpacklo_epi16(descs[0], descs[1]);
171 ptype1 = _mm_unpacklo_epi16(descs[2], descs[3]);
172 vtag0 = _mm_unpackhi_epi16(descs[0], descs[1]);
173 vtag1 = _mm_unpackhi_epi16(descs[2], descs[3]);
175 ptype0 = _mm_unpacklo_epi32(ptype0, ptype1);
176 ptype0 = _mm_and_si128(ptype0, rsstype_msk);
177 ptype0 = _mm_shuffle_epi8(rss_flags, ptype0);
179 vtag1 = _mm_unpacklo_epi32(vtag0, vtag1);
180 vtag1 = _mm_srli_epi16(vtag1, VTAG_SHIFT);
181 vtag1 = _mm_and_si128(vtag1, pkttype_msk);
183 vtag1 = _mm_or_si128(ptype0, vtag1);
184 vol.dword = _mm_cvtsi128_si64(vtag1);
186 rx_pkts[0]->ol_flags = vol.e[0];
187 rx_pkts[1]->ol_flags = vol.e[1];
188 rx_pkts[2]->ol_flags = vol.e[2];
189 rx_pkts[3]->ol_flags = vol.e[3];
192 #define desc_to_olflags_v(desc, rx_pkts) do {} while (0)
196 * vPMD raw receive routine, only accept(nb_pkts >= RTE_IXGBE_DESCS_PER_LOOP)
199 * - nb_pkts < RTE_IXGBE_DESCS_PER_LOOP, just return no packet
200 * - nb_pkts > RTE_IXGBE_MAX_RX_BURST, only scan RTE_IXGBE_MAX_RX_BURST
202 * - floor align nb_pkts to a RTE_IXGBE_DESC_PER_LOOP power-of-two
203 * - don't support ol_flags for rss and csum err
205 static inline uint16_t
206 _recv_raw_pkts_vec(struct ixgbe_rx_queue *rxq, struct rte_mbuf **rx_pkts,
207 uint16_t nb_pkts, uint8_t *split_packet)
209 volatile union ixgbe_adv_rx_desc *rxdp;
210 struct ixgbe_rx_entry *sw_ring;
211 uint16_t nb_pkts_recd;
215 __m128i crc_adjust = _mm_set_epi16(
216 0, 0, 0, /* ignore non-length fields */
217 -rxq->crc_len, /* sub crc on data_len */
218 0, /* ignore high-16bits of pkt_len */
219 -rxq->crc_len, /* sub crc on pkt_len */
220 0, 0 /* ignore pkt_type field */
222 __m128i dd_check, eop_check;
223 __m128i desc_mask = _mm_set_epi32(0xFFFFFFFF, 0xFFFFFFFF,
224 0xFFFFFFFF, 0xFFFF07F0);
226 /* nb_pkts shall be less equal than RTE_IXGBE_MAX_RX_BURST */
227 nb_pkts = RTE_MIN(nb_pkts, RTE_IXGBE_MAX_RX_BURST);
229 /* nb_pkts has to be floor-aligned to RTE_IXGBE_DESCS_PER_LOOP */
230 nb_pkts = RTE_ALIGN_FLOOR(nb_pkts, RTE_IXGBE_DESCS_PER_LOOP);
232 /* Just the act of getting into the function from the application is
233 * going to cost about 7 cycles */
234 rxdp = rxq->rx_ring + rxq->rx_tail;
236 _mm_prefetch((const void *)rxdp, _MM_HINT_T0);
238 /* See if we need to rearm the RX queue - gives the prefetch a bit
240 if (rxq->rxrearm_nb > RTE_IXGBE_RXQ_REARM_THRESH)
241 ixgbe_rxq_rearm(rxq);
243 /* Before we start moving massive data around, check to see if
244 * there is actually a packet available */
245 if (!(rxdp->wb.upper.status_error &
246 rte_cpu_to_le_32(IXGBE_RXDADV_STAT_DD)))
249 /* 4 packets DD mask */
250 dd_check = _mm_set_epi64x(0x0000000100000001LL, 0x0000000100000001LL);
252 /* 4 packets EOP mask */
253 eop_check = _mm_set_epi64x(0x0000000200000002LL, 0x0000000200000002LL);
255 /* mask to shuffle from desc. to mbuf */
256 shuf_msk = _mm_set_epi8(
257 7, 6, 5, 4, /* octet 4~7, 32bits rss */
258 15, 14, /* octet 14~15, low 16 bits vlan_macip */
259 13, 12, /* octet 12~13, 16 bits data_len */
260 0xFF, 0xFF, /* skip high 16 bits pkt_len, zero out */
261 13, 12, /* octet 12~13, low 16 bits pkt_len */
262 0xFF, 0xFF, /* skip high 16 bits pkt_type */
263 1, /* octet 1, 8 bits pkt_type field */
264 0 /* octet 0, 4 bits offset 4 pkt_type field */
267 /* Cache is empty -> need to scan the buffer rings, but first move
268 * the next 'n' mbufs into the cache */
269 sw_ring = &rxq->sw_ring[rxq->rx_tail];
271 /* A. load 4 packet in one loop
272 * [A*. mask out 4 unused dirty field in desc]
273 * B. copy 4 mbuf point from swring to rx_pkts
274 * C. calc the number of DD bits among the 4 packets
275 * [C*. extract the end-of-packet bit, if requested]
276 * D. fill info. from desc to mbuf
278 for (pos = 0, nb_pkts_recd = 0; pos < nb_pkts;
279 pos += RTE_IXGBE_DESCS_PER_LOOP,
280 rxdp += RTE_IXGBE_DESCS_PER_LOOP) {
281 __m128i descs0[RTE_IXGBE_DESCS_PER_LOOP];
282 __m128i descs[RTE_IXGBE_DESCS_PER_LOOP];
283 __m128i pkt_mb1, pkt_mb2, pkt_mb3, pkt_mb4;
284 __m128i zero, staterr, sterr_tmp1, sterr_tmp2;
285 __m128i mbp1, mbp2; /* two mbuf pointer in one XMM reg. */
287 /* B.1 load 1 mbuf point */
288 mbp1 = _mm_loadu_si128((__m128i *)&sw_ring[pos]);
290 /* Read desc statuses backwards to avoid race condition */
291 /* A.1 load 4 pkts desc */
292 descs0[3] = _mm_loadu_si128((__m128i *)(rxdp + 3));
294 /* B.2 copy 2 mbuf point into rx_pkts */
295 _mm_storeu_si128((__m128i *)&rx_pkts[pos], mbp1);
297 /* B.1 load 1 mbuf point */
298 mbp2 = _mm_loadu_si128((__m128i *)&sw_ring[pos+2]);
300 descs0[2] = _mm_loadu_si128((__m128i *)(rxdp + 2));
301 /* B.1 load 2 mbuf point */
302 descs0[1] = _mm_loadu_si128((__m128i *)(rxdp + 1));
303 descs0[0] = _mm_loadu_si128((__m128i *)(rxdp));
305 /* B.2 copy 2 mbuf point into rx_pkts */
306 _mm_storeu_si128((__m128i *)&rx_pkts[pos+2], mbp2);
309 rte_prefetch0(&rx_pkts[pos]->cacheline1);
310 rte_prefetch0(&rx_pkts[pos + 1]->cacheline1);
311 rte_prefetch0(&rx_pkts[pos + 2]->cacheline1);
312 rte_prefetch0(&rx_pkts[pos + 3]->cacheline1);
315 /* A* mask out 0~3 bits RSS type */
316 descs[3] = _mm_and_si128(descs0[3], desc_mask);
317 descs[2] = _mm_and_si128(descs0[2], desc_mask);
319 /* A* mask out 0~3 bits RSS type */
320 descs[1] = _mm_and_si128(descs0[1], desc_mask);
321 descs[0] = _mm_and_si128(descs0[0], desc_mask);
323 /* avoid compiler reorder optimization */
324 rte_compiler_barrier();
326 /* D.1 pkt 3,4 convert format from desc to pktmbuf */
327 pkt_mb4 = _mm_shuffle_epi8(descs[3], shuf_msk);
328 pkt_mb3 = _mm_shuffle_epi8(descs[2], shuf_msk);
330 /* C.1 4=>2 filter staterr info only */
331 sterr_tmp2 = _mm_unpackhi_epi32(descs[3], descs[2]);
332 /* C.1 4=>2 filter staterr info only */
333 sterr_tmp1 = _mm_unpackhi_epi32(descs[1], descs[0]);
335 /* set ol_flags with vlan packet type */
336 desc_to_olflags_v(descs0, &rx_pkts[pos]);
338 /* D.2 pkt 3,4 set in_port/nb_seg and remove crc */
339 pkt_mb4 = _mm_add_epi16(pkt_mb4, crc_adjust);
340 pkt_mb3 = _mm_add_epi16(pkt_mb3, crc_adjust);
342 /* D.1 pkt 1,2 convert format from desc to pktmbuf */
343 pkt_mb2 = _mm_shuffle_epi8(descs[1], shuf_msk);
344 pkt_mb1 = _mm_shuffle_epi8(descs[0], shuf_msk);
346 /* C.2 get 4 pkts staterr value */
347 zero = _mm_xor_si128(dd_check, dd_check);
348 staterr = _mm_unpacklo_epi32(sterr_tmp1, sterr_tmp2);
350 /* D.3 copy final 3,4 data to rx_pkts */
351 _mm_storeu_si128((void *)&rx_pkts[pos+3]->rx_descriptor_fields1,
353 _mm_storeu_si128((void *)&rx_pkts[pos+2]->rx_descriptor_fields1,
356 /* D.2 pkt 1,2 set in_port/nb_seg and remove crc */
357 pkt_mb2 = _mm_add_epi16(pkt_mb2, crc_adjust);
358 pkt_mb1 = _mm_add_epi16(pkt_mb1, crc_adjust);
360 /* C* extract and record EOP bit */
362 __m128i eop_shuf_mask = _mm_set_epi8(
363 0xFF, 0xFF, 0xFF, 0xFF,
364 0xFF, 0xFF, 0xFF, 0xFF,
365 0xFF, 0xFF, 0xFF, 0xFF,
366 0x04, 0x0C, 0x00, 0x08
369 /* and with mask to extract bits, flipping 1-0 */
370 __m128i eop_bits = _mm_andnot_si128(staterr, eop_check);
371 /* the staterr values are not in order, as the count
372 * count of dd bits doesn't care. However, for end of
373 * packet tracking, we do care, so shuffle. This also
374 * compresses the 32-bit values to 8-bit */
375 eop_bits = _mm_shuffle_epi8(eop_bits, eop_shuf_mask);
376 /* store the resulting 32-bit value */
377 *(int *)split_packet = _mm_cvtsi128_si32(eop_bits);
378 split_packet += RTE_IXGBE_DESCS_PER_LOOP;
380 /* zero-out next pointers */
381 rx_pkts[pos]->next = NULL;
382 rx_pkts[pos + 1]->next = NULL;
383 rx_pkts[pos + 2]->next = NULL;
384 rx_pkts[pos + 3]->next = NULL;
387 /* C.3 calc available number of desc */
388 staterr = _mm_and_si128(staterr, dd_check);
389 staterr = _mm_packs_epi32(staterr, zero);
391 /* D.3 copy final 1,2 data to rx_pkts */
392 _mm_storeu_si128((void *)&rx_pkts[pos+1]->rx_descriptor_fields1,
394 _mm_storeu_si128((void *)&rx_pkts[pos]->rx_descriptor_fields1,
397 /* C.4 calc avaialbe number of desc */
398 var = __builtin_popcountll(_mm_cvtsi128_si64(staterr));
400 if (likely(var != RTE_IXGBE_DESCS_PER_LOOP))
404 /* Update our internal tail pointer */
405 rxq->rx_tail = (uint16_t)(rxq->rx_tail + nb_pkts_recd);
406 rxq->rx_tail = (uint16_t)(rxq->rx_tail & (rxq->nb_rx_desc - 1));
407 rxq->rxrearm_nb = (uint16_t)(rxq->rxrearm_nb + nb_pkts_recd);
413 * vPMD receive routine, only accept(nb_pkts >= RTE_IXGBE_DESCS_PER_LOOP)
416 * - nb_pkts < RTE_IXGBE_DESCS_PER_LOOP, just return no packet
417 * - nb_pkts > RTE_IXGBE_MAX_RX_BURST, only scan RTE_IXGBE_MAX_RX_BURST
419 * - floor align nb_pkts to a RTE_IXGBE_DESC_PER_LOOP power-of-two
420 * - don't support ol_flags for rss and csum err
423 ixgbe_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
426 return _recv_raw_pkts_vec(rx_queue, rx_pkts, nb_pkts, NULL);
429 static inline uint16_t
430 reassemble_packets(struct ixgbe_rx_queue *rxq, struct rte_mbuf **rx_bufs,
431 uint16_t nb_bufs, uint8_t *split_flags)
433 struct rte_mbuf *pkts[nb_bufs]; /*finished pkts*/
434 struct rte_mbuf *start = rxq->pkt_first_seg;
435 struct rte_mbuf *end = rxq->pkt_last_seg;
436 unsigned pkt_idx, buf_idx;
438 for (buf_idx = 0, pkt_idx = 0; buf_idx < nb_bufs; buf_idx++) {
440 /* processing a split packet */
441 end->next = rx_bufs[buf_idx];
442 rx_bufs[buf_idx]->data_len += rxq->crc_len;
445 start->pkt_len += rx_bufs[buf_idx]->data_len;
448 if (!split_flags[buf_idx]) {
449 /* it's the last packet of the set */
450 start->hash = end->hash;
451 start->ol_flags = end->ol_flags;
452 /* we need to strip crc for the whole packet */
453 start->pkt_len -= rxq->crc_len;
454 if (end->data_len > rxq->crc_len)
455 end->data_len -= rxq->crc_len;
457 /* free up last mbuf */
458 struct rte_mbuf *secondlast = start;
461 while (secondlast->next != end)
462 secondlast = secondlast->next;
463 secondlast->data_len -= (rxq->crc_len -
465 secondlast->next = NULL;
466 rte_pktmbuf_free_seg(end);
469 pkts[pkt_idx++] = start;
473 /* not processing a split packet */
474 if (!split_flags[buf_idx]) {
475 /* not a split packet, save and skip */
476 pkts[pkt_idx++] = rx_bufs[buf_idx];
479 end = start = rx_bufs[buf_idx];
480 rx_bufs[buf_idx]->data_len += rxq->crc_len;
481 rx_bufs[buf_idx]->pkt_len += rxq->crc_len;
485 /* save the partial packet for next time */
486 rxq->pkt_first_seg = start;
487 rxq->pkt_last_seg = end;
488 memcpy(rx_bufs, pkts, pkt_idx * (sizeof(*pkts)));
493 * vPMD receive routine that reassembles scattered packets
496 * - don't support ol_flags for rss and csum err
497 * - nb_pkts < RTE_IXGBE_DESCS_PER_LOOP, just return no packet
498 * - nb_pkts > RTE_IXGBE_MAX_RX_BURST, only scan RTE_IXGBE_MAX_RX_BURST
500 * - floor align nb_pkts to a RTE_IXGBE_DESC_PER_LOOP power-of-two
503 ixgbe_recv_scattered_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
506 struct ixgbe_rx_queue *rxq = rx_queue;
507 uint8_t split_flags[RTE_IXGBE_MAX_RX_BURST] = {0};
509 /* get some new buffers */
510 uint16_t nb_bufs = _recv_raw_pkts_vec(rxq, rx_pkts, nb_pkts,
515 /* happy day case, full burst + no packets to be joined */
516 const uint64_t *split_fl64 = (uint64_t *)split_flags;
517 if (rxq->pkt_first_seg == NULL &&
518 split_fl64[0] == 0 && split_fl64[1] == 0 &&
519 split_fl64[2] == 0 && split_fl64[3] == 0)
522 /* reassemble any packets that need reassembly*/
524 if (rxq->pkt_first_seg == NULL) {
525 /* find the first split flag, and only reassemble then*/
526 while (i < nb_bufs && !split_flags[i])
531 return i + reassemble_packets(rxq, &rx_pkts[i], nb_bufs - i,
536 vtx1(volatile union ixgbe_adv_tx_desc *txdp,
537 struct rte_mbuf *pkt, uint64_t flags)
539 __m128i descriptor = _mm_set_epi64x((uint64_t)pkt->pkt_len << 46 |
540 flags | pkt->data_len,
541 pkt->buf_physaddr + pkt->data_off);
542 _mm_store_si128((__m128i *)&txdp->read, descriptor);
546 vtx(volatile union ixgbe_adv_tx_desc *txdp,
547 struct rte_mbuf **pkt, uint16_t nb_pkts, uint64_t flags)
550 for (i = 0; i < nb_pkts; ++i, ++txdp, ++pkt)
551 vtx1(txdp, *pkt, flags);
554 static inline int __attribute__((always_inline))
555 ixgbe_tx_free_bufs(struct ixgbe_tx_queue *txq)
557 struct ixgbe_tx_entry_v *txep;
562 struct rte_mbuf *m, *free[RTE_IXGBE_TX_MAX_FREE_BUF_SZ];
564 /* check DD bit on threshold descriptor */
565 status = txq->tx_ring[txq->tx_next_dd].wb.status;
566 if (!(status & IXGBE_ADVTXD_STAT_DD))
569 n = txq->tx_rs_thresh;
572 * first buffer to free from S/W ring is at index
573 * tx_next_dd - (tx_rs_thresh-1)
575 txep = &txq->sw_ring_v[txq->tx_next_dd - (n - 1)];
576 m = __rte_pktmbuf_prefree_seg(txep[0].mbuf);
577 if (likely(m != NULL)) {
580 for (i = 1; i < n; i++) {
581 m = __rte_pktmbuf_prefree_seg(txep[i].mbuf);
582 if (likely(m != NULL)) {
583 if (likely(m->pool == free[0]->pool))
586 rte_mempool_put_bulk(free[0]->pool,
587 (void *)free, nb_free);
593 rte_mempool_put_bulk(free[0]->pool, (void **)free, nb_free);
595 for (i = 1; i < n; i++) {
596 m = __rte_pktmbuf_prefree_seg(txep[i].mbuf);
598 rte_mempool_put(m->pool, m);
602 /* buffers were freed, update counters */
603 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + txq->tx_rs_thresh);
604 txq->tx_next_dd = (uint16_t)(txq->tx_next_dd + txq->tx_rs_thresh);
605 if (txq->tx_next_dd >= txq->nb_tx_desc)
606 txq->tx_next_dd = (uint16_t)(txq->tx_rs_thresh - 1);
608 return txq->tx_rs_thresh;
611 static inline void __attribute__((always_inline))
612 tx_backlog_entry(struct ixgbe_tx_entry_v *txep,
613 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
616 for (i = 0; i < (int)nb_pkts; ++i)
617 txep[i].mbuf = tx_pkts[i];
621 ixgbe_xmit_pkts_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
624 struct ixgbe_tx_queue *txq = (struct ixgbe_tx_queue *)tx_queue;
625 volatile union ixgbe_adv_tx_desc *txdp;
626 struct ixgbe_tx_entry_v *txep;
627 uint16_t n, nb_commit, tx_id;
628 uint64_t flags = DCMD_DTYP_FLAGS;
629 uint64_t rs = IXGBE_ADVTXD_DCMD_RS|DCMD_DTYP_FLAGS;
632 /* cross rx_thresh boundary is not allowed */
633 nb_pkts = RTE_MIN(nb_pkts, txq->tx_rs_thresh);
635 if (txq->nb_tx_free < txq->tx_free_thresh)
636 ixgbe_tx_free_bufs(txq);
638 nb_commit = nb_pkts = (uint16_t)RTE_MIN(txq->nb_tx_free, nb_pkts);
639 if (unlikely(nb_pkts == 0))
642 tx_id = txq->tx_tail;
643 txdp = &txq->tx_ring[tx_id];
644 txep = &txq->sw_ring_v[tx_id];
646 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_pkts);
648 n = (uint16_t)(txq->nb_tx_desc - tx_id);
649 if (nb_commit >= n) {
651 tx_backlog_entry(txep, tx_pkts, n);
653 for (i = 0; i < n - 1; ++i, ++tx_pkts, ++txdp)
654 vtx1(txdp, *tx_pkts, flags);
656 vtx1(txdp, *tx_pkts++, rs);
658 nb_commit = (uint16_t)(nb_commit - n);
661 txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
663 /* avoid reach the end of ring */
664 txdp = &(txq->tx_ring[tx_id]);
665 txep = &txq->sw_ring_v[tx_id];
668 tx_backlog_entry(txep, tx_pkts, nb_commit);
670 vtx(txdp, tx_pkts, nb_commit, flags);
672 tx_id = (uint16_t)(tx_id + nb_commit);
673 if (tx_id > txq->tx_next_rs) {
674 txq->tx_ring[txq->tx_next_rs].read.cmd_type_len |=
675 rte_cpu_to_le_32(IXGBE_ADVTXD_DCMD_RS);
676 txq->tx_next_rs = (uint16_t)(txq->tx_next_rs +
680 txq->tx_tail = tx_id;
682 IXGBE_PCI_REG_WRITE(txq->tdt_reg_addr, txq->tx_tail);
687 static void __attribute__((cold))
688 ixgbe_tx_queue_release_mbufs_vec(struct ixgbe_tx_queue *txq)
691 struct ixgbe_tx_entry_v *txe;
692 const uint16_t max_desc = (uint16_t)(txq->nb_tx_desc - 1);
694 if (txq->sw_ring == NULL || txq->nb_tx_free == max_desc)
697 /* release the used mbufs in sw_ring */
698 for (i = txq->tx_next_dd - (txq->tx_rs_thresh - 1);
700 i = (i + 1) & max_desc) {
701 txe = &txq->sw_ring_v[i];
702 rte_pktmbuf_free_seg(txe->mbuf);
704 txq->nb_tx_free = max_desc;
707 for (i = 0; i < txq->nb_tx_desc; i++) {
708 txe = &txq->sw_ring_v[i];
713 void __attribute__((cold))
714 ixgbe_rx_queue_release_mbufs_vec(struct ixgbe_rx_queue *rxq)
716 const unsigned mask = rxq->nb_rx_desc - 1;
719 if (rxq->sw_ring == NULL || rxq->rxrearm_nb >= rxq->nb_rx_desc)
722 /* free all mbufs that are valid in the ring */
723 for (i = rxq->rx_tail; i != rxq->rxrearm_start; i = (i + 1) & mask)
724 rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf);
725 rxq->rxrearm_nb = rxq->nb_rx_desc;
727 /* set all entries to NULL */
728 memset(rxq->sw_ring, 0, sizeof(rxq->sw_ring[0]) * rxq->nb_rx_desc);
731 static void __attribute__((cold))
732 ixgbe_tx_free_swring(struct ixgbe_tx_queue *txq)
737 if (txq->sw_ring != NULL) {
738 rte_free(txq->sw_ring_v - 1);
739 txq->sw_ring_v = NULL;
743 static void __attribute__((cold))
744 ixgbe_reset_tx_queue(struct ixgbe_tx_queue *txq)
746 static const union ixgbe_adv_tx_desc zeroed_desc = {{0}};
747 struct ixgbe_tx_entry_v *txe = txq->sw_ring_v;
750 /* Zero out HW ring memory */
751 for (i = 0; i < txq->nb_tx_desc; i++)
752 txq->tx_ring[i] = zeroed_desc;
754 /* Initialize SW ring entries */
755 for (i = 0; i < txq->nb_tx_desc; i++) {
756 volatile union ixgbe_adv_tx_desc *txd = &txq->tx_ring[i];
757 txd->wb.status = IXGBE_TXD_STAT_DD;
761 txq->tx_next_dd = (uint16_t)(txq->tx_rs_thresh - 1);
762 txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
767 * Always allow 1 descriptor to be un-allocated to avoid
768 * a H/W race condition
770 txq->last_desc_cleaned = (uint16_t)(txq->nb_tx_desc - 1);
771 txq->nb_tx_free = (uint16_t)(txq->nb_tx_desc - 1);
773 memset((void *)&txq->ctx_cache, 0,
774 IXGBE_CTX_NUM * sizeof(struct ixgbe_advctx_info));
777 static const struct ixgbe_txq_ops vec_txq_ops = {
778 .release_mbufs = ixgbe_tx_queue_release_mbufs_vec,
779 .free_swring = ixgbe_tx_free_swring,
780 .reset = ixgbe_reset_tx_queue,
783 int __attribute__((cold))
784 ixgbe_rxq_vec_setup(struct ixgbe_rx_queue *rxq)
787 struct rte_mbuf mb_def = { .buf_addr = 0 }; /* zeroed mbuf */
790 mb_def.data_off = RTE_PKTMBUF_HEADROOM;
791 mb_def.port = rxq->port_id;
792 rte_mbuf_refcnt_set(&mb_def, 1);
794 /* prevent compiler reordering: rearm_data covers previous fields */
795 rte_compiler_barrier();
796 p = (uintptr_t)&mb_def.rearm_data;
797 rxq->mbuf_initializer = *(uint64_t *)p;
801 int __attribute__((cold))
802 ixgbe_txq_vec_setup(struct ixgbe_tx_queue *txq)
804 if (txq->sw_ring_v == NULL)
807 /* leave the first one for overflow */
808 txq->sw_ring_v = txq->sw_ring_v + 1;
809 txq->ops = &vec_txq_ops;
814 int __attribute__((cold))
815 ixgbe_rx_vec_dev_conf_condition_check(struct rte_eth_dev *dev)
817 #ifndef RTE_LIBRTE_IEEE1588
818 struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
819 struct rte_fdir_conf *fconf = &dev->data->dev_conf.fdir_conf;
821 #ifndef RTE_IXGBE_RX_OLFLAGS_ENABLE
822 /* whithout rx ol_flags, no VP flag report */
823 if (rxmode->hw_vlan_strip != 0 ||
824 rxmode->hw_vlan_extend != 0)
828 /* no fdir support */
829 if (fconf->mode != RTE_FDIR_MODE_NONE)
833 * - no csum error report support
834 * - no header split support
836 if (rxmode->hw_ip_checksum == 1 ||
837 rxmode->header_split == 1)