mbuf: make rearm data address naturally aligned
[dpdk.git] / drivers / net / ixgbe / ixgbe_rxtx_vec_sse.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <stdint.h>
35 #include <rte_ethdev.h>
36 #include <rte_malloc.h>
37
38 #include "ixgbe_ethdev.h"
39 #include "ixgbe_rxtx.h"
40 #include "ixgbe_rxtx_vec_common.h"
41
42 #include <tmmintrin.h>
43
44 #ifndef __INTEL_COMPILER
45 #pragma GCC diagnostic ignored "-Wcast-qual"
46 #endif
47
48 static inline void
49 ixgbe_rxq_rearm(struct ixgbe_rx_queue *rxq)
50 {
51         int i;
52         uint16_t rx_id;
53         volatile union ixgbe_adv_rx_desc *rxdp;
54         struct ixgbe_rx_entry *rxep = &rxq->sw_ring[rxq->rxrearm_start];
55         struct rte_mbuf *mb0, *mb1;
56         __m128i hdr_room = _mm_set_epi64x(RTE_PKTMBUF_HEADROOM,
57                         RTE_PKTMBUF_HEADROOM);
58         __m128i dma_addr0, dma_addr1;
59
60         const __m128i hba_msk = _mm_set_epi64x(0, UINT64_MAX);
61
62         rxdp = rxq->rx_ring + rxq->rxrearm_start;
63
64         /* Pull 'n' more MBUFs into the software ring */
65         if (rte_mempool_get_bulk(rxq->mb_pool,
66                                  (void *)rxep,
67                                  RTE_IXGBE_RXQ_REARM_THRESH) < 0) {
68                 if (rxq->rxrearm_nb + RTE_IXGBE_RXQ_REARM_THRESH >=
69                     rxq->nb_rx_desc) {
70                         dma_addr0 = _mm_setzero_si128();
71                         for (i = 0; i < RTE_IXGBE_DESCS_PER_LOOP; i++) {
72                                 rxep[i].mbuf = &rxq->fake_mbuf;
73                                 _mm_store_si128((__m128i *)&rxdp[i].read,
74                                                 dma_addr0);
75                         }
76                 }
77                 rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed +=
78                         RTE_IXGBE_RXQ_REARM_THRESH;
79                 return;
80         }
81
82         /* Initialize the mbufs in vector, process 2 mbufs in one loop */
83         for (i = 0; i < RTE_IXGBE_RXQ_REARM_THRESH; i += 2, rxep += 2) {
84                 __m128i vaddr0, vaddr1;
85                 uintptr_t p0, p1;
86
87                 mb0 = rxep[0].mbuf;
88                 mb1 = rxep[1].mbuf;
89
90                 /*
91                  * Flush mbuf with pkt template.
92                  * Data to be rearmed is 6 bytes long.
93                  */
94                 p0 = (uintptr_t)&mb0->rearm_data;
95                 *(uint64_t *)p0 = rxq->mbuf_initializer;
96                 p1 = (uintptr_t)&mb1->rearm_data;
97                 *(uint64_t *)p1 = rxq->mbuf_initializer;
98
99                 /* load buf_addr(lo 64bit) and buf_physaddr(hi 64bit) */
100                 vaddr0 = _mm_loadu_si128((__m128i *)&(mb0->buf_addr));
101                 vaddr1 = _mm_loadu_si128((__m128i *)&(mb1->buf_addr));
102
103                 /* convert pa to dma_addr hdr/data */
104                 dma_addr0 = _mm_unpackhi_epi64(vaddr0, vaddr0);
105                 dma_addr1 = _mm_unpackhi_epi64(vaddr1, vaddr1);
106
107                 /* add headroom to pa values */
108                 dma_addr0 = _mm_add_epi64(dma_addr0, hdr_room);
109                 dma_addr1 = _mm_add_epi64(dma_addr1, hdr_room);
110
111                 /* set Header Buffer Address to zero */
112                 dma_addr0 =  _mm_and_si128(dma_addr0, hba_msk);
113                 dma_addr1 =  _mm_and_si128(dma_addr1, hba_msk);
114
115                 /* flush desc with pa dma_addr */
116                 _mm_store_si128((__m128i *)&rxdp++->read, dma_addr0);
117                 _mm_store_si128((__m128i *)&rxdp++->read, dma_addr1);
118         }
119
120         rxq->rxrearm_start += RTE_IXGBE_RXQ_REARM_THRESH;
121         if (rxq->rxrearm_start >= rxq->nb_rx_desc)
122                 rxq->rxrearm_start = 0;
123
124         rxq->rxrearm_nb -= RTE_IXGBE_RXQ_REARM_THRESH;
125
126         rx_id = (uint16_t) ((rxq->rxrearm_start == 0) ?
127                              (rxq->nb_rx_desc - 1) : (rxq->rxrearm_start - 1));
128
129         /* Update the tail pointer on the NIC */
130         IXGBE_PCI_REG_WRITE(rxq->rdt_reg_addr, rx_id);
131 }
132
133 /* Handling the offload flags (olflags) field takes computation
134  * time when receiving packets. Therefore we provide a flag to disable
135  * the processing of the olflags field when they are not needed. This
136  * gives improved performance, at the cost of losing the offload info
137  * in the received packet
138  */
139 #ifdef RTE_IXGBE_RX_OLFLAGS_ENABLE
140
141 static inline void
142 desc_to_olflags_v(__m128i descs[4], uint8_t vlan_flags,
143         struct rte_mbuf **rx_pkts)
144 {
145         __m128i ptype0, ptype1, vtag0, vtag1, csum;
146         union {
147                 uint16_t e[4];
148                 uint64_t dword;
149         } vol;
150
151         /* mask everything except rss type */
152         const __m128i rsstype_msk = _mm_set_epi16(
153                         0x0000, 0x0000, 0x0000, 0x0000,
154                         0x000F, 0x000F, 0x000F, 0x000F);
155
156         /* mask the lower byte of ol_flags */
157         const __m128i ol_flags_msk = _mm_set_epi16(
158                         0x0000, 0x0000, 0x0000, 0x0000,
159                         0x00FF, 0x00FF, 0x00FF, 0x00FF);
160
161         /* map rss type to rss hash flag */
162         const __m128i rss_flags = _mm_set_epi8(PKT_RX_FDIR, 0, 0, 0,
163                         0, 0, 0, PKT_RX_RSS_HASH,
164                         PKT_RX_RSS_HASH, 0, PKT_RX_RSS_HASH, 0,
165                         PKT_RX_RSS_HASH, PKT_RX_RSS_HASH, PKT_RX_RSS_HASH, 0);
166
167         /* mask everything except vlan present and l4/ip csum error */
168         const __m128i vlan_csum_msk = _mm_set_epi16(
169                 (IXGBE_RXDADV_ERR_TCPE | IXGBE_RXDADV_ERR_IPE) >> 16,
170                 (IXGBE_RXDADV_ERR_TCPE | IXGBE_RXDADV_ERR_IPE) >> 16,
171                 (IXGBE_RXDADV_ERR_TCPE | IXGBE_RXDADV_ERR_IPE) >> 16,
172                 (IXGBE_RXDADV_ERR_TCPE | IXGBE_RXDADV_ERR_IPE) >> 16,
173                 IXGBE_RXD_STAT_VP, IXGBE_RXD_STAT_VP,
174                 IXGBE_RXD_STAT_VP, IXGBE_RXD_STAT_VP);
175         /* map vlan present (0x8), IPE (0x2), L4E (0x1) to ol_flags */
176         const __m128i vlan_csum_map_lo = _mm_set_epi8(
177                 0, 0, 0, 0,
178                 vlan_flags | PKT_RX_IP_CKSUM_BAD | PKT_RX_L4_CKSUM_BAD,
179                 vlan_flags | PKT_RX_IP_CKSUM_BAD,
180                 vlan_flags | PKT_RX_IP_CKSUM_GOOD | PKT_RX_L4_CKSUM_BAD,
181                 vlan_flags | PKT_RX_IP_CKSUM_GOOD,
182                 0, 0, 0, 0,
183                 PKT_RX_IP_CKSUM_BAD | PKT_RX_L4_CKSUM_BAD,
184                 PKT_RX_IP_CKSUM_BAD,
185                 PKT_RX_IP_CKSUM_GOOD | PKT_RX_L4_CKSUM_BAD,
186                 PKT_RX_IP_CKSUM_GOOD);
187
188         const __m128i vlan_csum_map_hi = _mm_set_epi8(
189                 0, 0, 0, 0,
190                 0, PKT_RX_L4_CKSUM_GOOD >> sizeof(uint8_t), 0,
191                 PKT_RX_L4_CKSUM_GOOD >> sizeof(uint8_t),
192                 0, 0, 0, 0,
193                 0, PKT_RX_L4_CKSUM_GOOD >> sizeof(uint8_t), 0,
194                 PKT_RX_L4_CKSUM_GOOD >> sizeof(uint8_t));
195
196         ptype0 = _mm_unpacklo_epi16(descs[0], descs[1]);
197         ptype1 = _mm_unpacklo_epi16(descs[2], descs[3]);
198         vtag0 = _mm_unpackhi_epi16(descs[0], descs[1]);
199         vtag1 = _mm_unpackhi_epi16(descs[2], descs[3]);
200
201         ptype0 = _mm_unpacklo_epi32(ptype0, ptype1);
202         ptype0 = _mm_and_si128(ptype0, rsstype_msk);
203         ptype0 = _mm_shuffle_epi8(rss_flags, ptype0);
204
205         vtag1 = _mm_unpacklo_epi32(vtag0, vtag1);
206         vtag1 = _mm_and_si128(vtag1, vlan_csum_msk);
207
208         /* csum bits are in the most significant, to use shuffle we need to
209          * shift them. Change mask to 0xc000 to 0x0003.
210          */
211         csum = _mm_srli_epi16(vtag1, 14);
212
213         /* now or the most significant 64 bits containing the checksum
214          * flags with the vlan present flags.
215          */
216         csum = _mm_srli_si128(csum, 8);
217         vtag1 = _mm_or_si128(csum, vtag1);
218
219         /* convert VP, IPE, L4E to ol_flags */
220         vtag0 = _mm_shuffle_epi8(vlan_csum_map_hi, vtag1);
221         vtag0 = _mm_slli_epi16(vtag0, sizeof(uint8_t));
222
223         vtag1 = _mm_shuffle_epi8(vlan_csum_map_lo, vtag1);
224         vtag1 = _mm_and_si128(vtag1, ol_flags_msk);
225         vtag1 = _mm_or_si128(vtag0, vtag1);
226
227         vtag1 = _mm_or_si128(ptype0, vtag1);
228         vol.dword = _mm_cvtsi128_si64(vtag1);
229
230         rx_pkts[0]->ol_flags = vol.e[0];
231         rx_pkts[1]->ol_flags = vol.e[1];
232         rx_pkts[2]->ol_flags = vol.e[2];
233         rx_pkts[3]->ol_flags = vol.e[3];
234 }
235 #else
236 #define desc_to_olflags_v(desc, vlan_flags, rx_pkts) do { \
237                 RTE_SET_USED(vlan_flags); \
238         } while (0)
239 #endif
240
241 /*
242  * vPMD raw receive routine, only accept(nb_pkts >= RTE_IXGBE_DESCS_PER_LOOP)
243  *
244  * Notice:
245  * - nb_pkts < RTE_IXGBE_DESCS_PER_LOOP, just return no packet
246  * - nb_pkts > RTE_IXGBE_MAX_RX_BURST, only scan RTE_IXGBE_MAX_RX_BURST
247  *   numbers of DD bit
248  * - floor align nb_pkts to a RTE_IXGBE_DESC_PER_LOOP power-of-two
249  */
250 static inline uint16_t
251 _recv_raw_pkts_vec(struct ixgbe_rx_queue *rxq, struct rte_mbuf **rx_pkts,
252                 uint16_t nb_pkts, uint8_t *split_packet)
253 {
254         volatile union ixgbe_adv_rx_desc *rxdp;
255         struct ixgbe_rx_entry *sw_ring;
256         uint16_t nb_pkts_recd;
257         int pos;
258         uint64_t var;
259         __m128i shuf_msk;
260         __m128i crc_adjust = _mm_set_epi16(
261                                 0, 0, 0,    /* ignore non-length fields */
262                                 -rxq->crc_len, /* sub crc on data_len */
263                                 0,          /* ignore high-16bits of pkt_len */
264                                 -rxq->crc_len, /* sub crc on pkt_len */
265                                 0, 0            /* ignore pkt_type field */
266                         );
267         __m128i dd_check, eop_check;
268         uint8_t vlan_flags;
269
270         /* nb_pkts shall be less equal than RTE_IXGBE_MAX_RX_BURST */
271         nb_pkts = RTE_MIN(nb_pkts, RTE_IXGBE_MAX_RX_BURST);
272
273         /* nb_pkts has to be floor-aligned to RTE_IXGBE_DESCS_PER_LOOP */
274         nb_pkts = RTE_ALIGN_FLOOR(nb_pkts, RTE_IXGBE_DESCS_PER_LOOP);
275
276         /* Just the act of getting into the function from the application is
277          * going to cost about 7 cycles
278          */
279         rxdp = rxq->rx_ring + rxq->rx_tail;
280
281         rte_prefetch0(rxdp);
282
283         /* See if we need to rearm the RX queue - gives the prefetch a bit
284          * of time to act
285          */
286         if (rxq->rxrearm_nb > RTE_IXGBE_RXQ_REARM_THRESH)
287                 ixgbe_rxq_rearm(rxq);
288
289         /* Before we start moving massive data around, check to see if
290          * there is actually a packet available
291          */
292         if (!(rxdp->wb.upper.status_error &
293                                 rte_cpu_to_le_32(IXGBE_RXDADV_STAT_DD)))
294                 return 0;
295
296         /* 4 packets DD mask */
297         dd_check = _mm_set_epi64x(0x0000000100000001LL, 0x0000000100000001LL);
298
299         /* 4 packets EOP mask */
300         eop_check = _mm_set_epi64x(0x0000000200000002LL, 0x0000000200000002LL);
301
302         /* mask to shuffle from desc. to mbuf */
303         shuf_msk = _mm_set_epi8(
304                 7, 6, 5, 4,  /* octet 4~7, 32bits rss */
305                 15, 14,      /* octet 14~15, low 16 bits vlan_macip */
306                 13, 12,      /* octet 12~13, 16 bits data_len */
307                 0xFF, 0xFF,  /* skip high 16 bits pkt_len, zero out */
308                 13, 12,      /* octet 12~13, low 16 bits pkt_len */
309                 0xFF, 0xFF,  /* skip 32 bit pkt_type */
310                 0xFF, 0xFF
311                 );
312
313         /* Cache is empty -> need to scan the buffer rings, but first move
314          * the next 'n' mbufs into the cache
315          */
316         sw_ring = &rxq->sw_ring[rxq->rx_tail];
317
318         /* ensure these 2 flags are in the lower 8 bits */
319         RTE_BUILD_BUG_ON((PKT_RX_VLAN_PKT | PKT_RX_VLAN_STRIPPED) > UINT8_MAX);
320         vlan_flags = rxq->vlan_flags & UINT8_MAX;
321
322         /* A. load 4 packet in one loop
323          * [A*. mask out 4 unused dirty field in desc]
324          * B. copy 4 mbuf point from swring to rx_pkts
325          * C. calc the number of DD bits among the 4 packets
326          * [C*. extract the end-of-packet bit, if requested]
327          * D. fill info. from desc to mbuf
328          */
329         for (pos = 0, nb_pkts_recd = 0; pos < nb_pkts;
330                         pos += RTE_IXGBE_DESCS_PER_LOOP,
331                         rxdp += RTE_IXGBE_DESCS_PER_LOOP) {
332                 __m128i descs[RTE_IXGBE_DESCS_PER_LOOP];
333                 __m128i pkt_mb1, pkt_mb2, pkt_mb3, pkt_mb4;
334                 __m128i zero, staterr, sterr_tmp1, sterr_tmp2;
335                 __m128i mbp1, mbp2; /* two mbuf pointer in one XMM reg. */
336
337                 /* B.1 load 1 mbuf point */
338                 mbp1 = _mm_loadu_si128((__m128i *)&sw_ring[pos]);
339
340                 /* Read desc statuses backwards to avoid race condition */
341                 /* A.1 load 4 pkts desc */
342                 descs[3] = _mm_loadu_si128((__m128i *)(rxdp + 3));
343                 rte_compiler_barrier();
344
345                 /* B.2 copy 2 mbuf point into rx_pkts  */
346                 _mm_storeu_si128((__m128i *)&rx_pkts[pos], mbp1);
347
348                 /* B.1 load 1 mbuf point */
349                 mbp2 = _mm_loadu_si128((__m128i *)&sw_ring[pos+2]);
350
351                 descs[2] = _mm_loadu_si128((__m128i *)(rxdp + 2));
352                 rte_compiler_barrier();
353                 /* B.1 load 2 mbuf point */
354                 descs[1] = _mm_loadu_si128((__m128i *)(rxdp + 1));
355                 rte_compiler_barrier();
356                 descs[0] = _mm_loadu_si128((__m128i *)(rxdp));
357
358                 /* B.2 copy 2 mbuf point into rx_pkts  */
359                 _mm_storeu_si128((__m128i *)&rx_pkts[pos+2], mbp2);
360
361                 if (split_packet) {
362                         rte_mbuf_prefetch_part2(rx_pkts[pos]);
363                         rte_mbuf_prefetch_part2(rx_pkts[pos + 1]);
364                         rte_mbuf_prefetch_part2(rx_pkts[pos + 2]);
365                         rte_mbuf_prefetch_part2(rx_pkts[pos + 3]);
366                 }
367
368                 /* avoid compiler reorder optimization */
369                 rte_compiler_barrier();
370
371                 /* D.1 pkt 3,4 convert format from desc to pktmbuf */
372                 pkt_mb4 = _mm_shuffle_epi8(descs[3], shuf_msk);
373                 pkt_mb3 = _mm_shuffle_epi8(descs[2], shuf_msk);
374
375                 /* D.1 pkt 1,2 convert format from desc to pktmbuf */
376                 pkt_mb2 = _mm_shuffle_epi8(descs[1], shuf_msk);
377                 pkt_mb1 = _mm_shuffle_epi8(descs[0], shuf_msk);
378
379                 /* C.1 4=>2 filter staterr info only */
380                 sterr_tmp2 = _mm_unpackhi_epi32(descs[3], descs[2]);
381                 /* C.1 4=>2 filter staterr info only */
382                 sterr_tmp1 = _mm_unpackhi_epi32(descs[1], descs[0]);
383
384                 /* set ol_flags with vlan packet type */
385                 desc_to_olflags_v(descs, vlan_flags, &rx_pkts[pos]);
386
387                 /* D.2 pkt 3,4 set in_port/nb_seg and remove crc */
388                 pkt_mb4 = _mm_add_epi16(pkt_mb4, crc_adjust);
389                 pkt_mb3 = _mm_add_epi16(pkt_mb3, crc_adjust);
390
391                 /* C.2 get 4 pkts staterr value  */
392                 zero = _mm_xor_si128(dd_check, dd_check);
393                 staterr = _mm_unpacklo_epi32(sterr_tmp1, sterr_tmp2);
394
395                 /* D.3 copy final 3,4 data to rx_pkts */
396                 _mm_storeu_si128((void *)&rx_pkts[pos+3]->rx_descriptor_fields1,
397                                 pkt_mb4);
398                 _mm_storeu_si128((void *)&rx_pkts[pos+2]->rx_descriptor_fields1,
399                                 pkt_mb3);
400
401                 /* D.2 pkt 1,2 set in_port/nb_seg and remove crc */
402                 pkt_mb2 = _mm_add_epi16(pkt_mb2, crc_adjust);
403                 pkt_mb1 = _mm_add_epi16(pkt_mb1, crc_adjust);
404
405                 /* C* extract and record EOP bit */
406                 if (split_packet) {
407                         __m128i eop_shuf_mask = _mm_set_epi8(
408                                         0xFF, 0xFF, 0xFF, 0xFF,
409                                         0xFF, 0xFF, 0xFF, 0xFF,
410                                         0xFF, 0xFF, 0xFF, 0xFF,
411                                         0x04, 0x0C, 0x00, 0x08
412                                         );
413
414                         /* and with mask to extract bits, flipping 1-0 */
415                         __m128i eop_bits = _mm_andnot_si128(staterr, eop_check);
416                         /* the staterr values are not in order, as the count
417                          * count of dd bits doesn't care. However, for end of
418                          * packet tracking, we do care, so shuffle. This also
419                          * compresses the 32-bit values to 8-bit
420                          */
421                         eop_bits = _mm_shuffle_epi8(eop_bits, eop_shuf_mask);
422                         /* store the resulting 32-bit value */
423                         *(int *)split_packet = _mm_cvtsi128_si32(eop_bits);
424                         split_packet += RTE_IXGBE_DESCS_PER_LOOP;
425                 }
426
427                 /* C.3 calc available number of desc */
428                 staterr = _mm_and_si128(staterr, dd_check);
429                 staterr = _mm_packs_epi32(staterr, zero);
430
431                 /* D.3 copy final 1,2 data to rx_pkts */
432                 _mm_storeu_si128((void *)&rx_pkts[pos+1]->rx_descriptor_fields1,
433                                 pkt_mb2);
434                 _mm_storeu_si128((void *)&rx_pkts[pos]->rx_descriptor_fields1,
435                                 pkt_mb1);
436
437                 /* C.4 calc avaialbe number of desc */
438                 var = __builtin_popcountll(_mm_cvtsi128_si64(staterr));
439                 nb_pkts_recd += var;
440                 if (likely(var != RTE_IXGBE_DESCS_PER_LOOP))
441                         break;
442         }
443
444         /* Update our internal tail pointer */
445         rxq->rx_tail = (uint16_t)(rxq->rx_tail + nb_pkts_recd);
446         rxq->rx_tail = (uint16_t)(rxq->rx_tail & (rxq->nb_rx_desc - 1));
447         rxq->rxrearm_nb = (uint16_t)(rxq->rxrearm_nb + nb_pkts_recd);
448
449         return nb_pkts_recd;
450 }
451
452 /*
453  * vPMD receive routine, only accept(nb_pkts >= RTE_IXGBE_DESCS_PER_LOOP)
454  *
455  * Notice:
456  * - nb_pkts < RTE_IXGBE_DESCS_PER_LOOP, just return no packet
457  * - nb_pkts > RTE_IXGBE_MAX_RX_BURST, only scan RTE_IXGBE_MAX_RX_BURST
458  *   numbers of DD bit
459  * - floor align nb_pkts to a RTE_IXGBE_DESC_PER_LOOP power-of-two
460  */
461 uint16_t
462 ixgbe_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
463                 uint16_t nb_pkts)
464 {
465         return _recv_raw_pkts_vec(rx_queue, rx_pkts, nb_pkts, NULL);
466 }
467
468 /*
469  * vPMD receive routine that reassembles scattered packets
470  *
471  * Notice:
472  * - nb_pkts < RTE_IXGBE_DESCS_PER_LOOP, just return no packet
473  * - nb_pkts > RTE_IXGBE_MAX_RX_BURST, only scan RTE_IXGBE_MAX_RX_BURST
474  *   numbers of DD bit
475  * - floor align nb_pkts to a RTE_IXGBE_DESC_PER_LOOP power-of-two
476  */
477 uint16_t
478 ixgbe_recv_scattered_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
479                 uint16_t nb_pkts)
480 {
481         struct ixgbe_rx_queue *rxq = rx_queue;
482         uint8_t split_flags[RTE_IXGBE_MAX_RX_BURST] = {0};
483
484         /* get some new buffers */
485         uint16_t nb_bufs = _recv_raw_pkts_vec(rxq, rx_pkts, nb_pkts,
486                         split_flags);
487         if (nb_bufs == 0)
488                 return 0;
489
490         /* happy day case, full burst + no packets to be joined */
491         const uint64_t *split_fl64 = (uint64_t *)split_flags;
492         if (rxq->pkt_first_seg == NULL &&
493                         split_fl64[0] == 0 && split_fl64[1] == 0 &&
494                         split_fl64[2] == 0 && split_fl64[3] == 0)
495                 return nb_bufs;
496
497         /* reassemble any packets that need reassembly*/
498         unsigned i = 0;
499         if (rxq->pkt_first_seg == NULL) {
500                 /* find the first split flag, and only reassemble then*/
501                 while (i < nb_bufs && !split_flags[i])
502                         i++;
503                 if (i == nb_bufs)
504                         return nb_bufs;
505         }
506         return i + reassemble_packets(rxq, &rx_pkts[i], nb_bufs - i,
507                 &split_flags[i]);
508 }
509
510 static inline void
511 vtx1(volatile union ixgbe_adv_tx_desc *txdp,
512                 struct rte_mbuf *pkt, uint64_t flags)
513 {
514         __m128i descriptor = _mm_set_epi64x((uint64_t)pkt->pkt_len << 46 |
515                         flags | pkt->data_len,
516                         pkt->buf_physaddr + pkt->data_off);
517         _mm_store_si128((__m128i *)&txdp->read, descriptor);
518 }
519
520 static inline void
521 vtx(volatile union ixgbe_adv_tx_desc *txdp,
522                 struct rte_mbuf **pkt, uint16_t nb_pkts,  uint64_t flags)
523 {
524         int i;
525
526         for (i = 0; i < nb_pkts; ++i, ++txdp, ++pkt)
527                 vtx1(txdp, *pkt, flags);
528 }
529
530 uint16_t
531 ixgbe_xmit_fixed_burst_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
532                            uint16_t nb_pkts)
533 {
534         struct ixgbe_tx_queue *txq = (struct ixgbe_tx_queue *)tx_queue;
535         volatile union ixgbe_adv_tx_desc *txdp;
536         struct ixgbe_tx_entry_v *txep;
537         uint16_t n, nb_commit, tx_id;
538         uint64_t flags = DCMD_DTYP_FLAGS;
539         uint64_t rs = IXGBE_ADVTXD_DCMD_RS|DCMD_DTYP_FLAGS;
540         int i;
541
542         /* cross rx_thresh boundary is not allowed */
543         nb_pkts = RTE_MIN(nb_pkts, txq->tx_rs_thresh);
544
545         if (txq->nb_tx_free < txq->tx_free_thresh)
546                 ixgbe_tx_free_bufs(txq);
547
548         nb_commit = nb_pkts = (uint16_t)RTE_MIN(txq->nb_tx_free, nb_pkts);
549         if (unlikely(nb_pkts == 0))
550                 return 0;
551
552         tx_id = txq->tx_tail;
553         txdp = &txq->tx_ring[tx_id];
554         txep = &txq->sw_ring_v[tx_id];
555
556         txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_pkts);
557
558         n = (uint16_t)(txq->nb_tx_desc - tx_id);
559         if (nb_commit >= n) {
560
561                 tx_backlog_entry(txep, tx_pkts, n);
562
563                 for (i = 0; i < n - 1; ++i, ++tx_pkts, ++txdp)
564                         vtx1(txdp, *tx_pkts, flags);
565
566                 vtx1(txdp, *tx_pkts++, rs);
567
568                 nb_commit = (uint16_t)(nb_commit - n);
569
570                 tx_id = 0;
571                 txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
572
573                 /* avoid reach the end of ring */
574                 txdp = &(txq->tx_ring[tx_id]);
575                 txep = &txq->sw_ring_v[tx_id];
576         }
577
578         tx_backlog_entry(txep, tx_pkts, nb_commit);
579
580         vtx(txdp, tx_pkts, nb_commit, flags);
581
582         tx_id = (uint16_t)(tx_id + nb_commit);
583         if (tx_id > txq->tx_next_rs) {
584                 txq->tx_ring[txq->tx_next_rs].read.cmd_type_len |=
585                         rte_cpu_to_le_32(IXGBE_ADVTXD_DCMD_RS);
586                 txq->tx_next_rs = (uint16_t)(txq->tx_next_rs +
587                         txq->tx_rs_thresh);
588         }
589
590         txq->tx_tail = tx_id;
591
592         IXGBE_PCI_REG_WRITE(txq->tdt_reg_addr, txq->tx_tail);
593
594         return nb_pkts;
595 }
596
597 static void __attribute__((cold))
598 ixgbe_tx_queue_release_mbufs_vec(struct ixgbe_tx_queue *txq)
599 {
600         _ixgbe_tx_queue_release_mbufs_vec(txq);
601 }
602
603 void __attribute__((cold))
604 ixgbe_rx_queue_release_mbufs_vec(struct ixgbe_rx_queue *rxq)
605 {
606         _ixgbe_rx_queue_release_mbufs_vec(rxq);
607 }
608
609 static void __attribute__((cold))
610 ixgbe_tx_free_swring(struct ixgbe_tx_queue *txq)
611 {
612         _ixgbe_tx_free_swring_vec(txq);
613 }
614
615 static void __attribute__((cold))
616 ixgbe_reset_tx_queue(struct ixgbe_tx_queue *txq)
617 {
618         _ixgbe_reset_tx_queue_vec(txq);
619 }
620
621 static const struct ixgbe_txq_ops vec_txq_ops = {
622         .release_mbufs = ixgbe_tx_queue_release_mbufs_vec,
623         .free_swring = ixgbe_tx_free_swring,
624         .reset = ixgbe_reset_tx_queue,
625 };
626
627 int __attribute__((cold))
628 ixgbe_rxq_vec_setup(struct ixgbe_rx_queue *rxq)
629 {
630         return ixgbe_rxq_vec_setup_default(rxq);
631 }
632
633 int __attribute__((cold))
634 ixgbe_txq_vec_setup(struct ixgbe_tx_queue *txq)
635 {
636         return ixgbe_txq_vec_setup_default(txq, &vec_txq_ops);
637 }
638
639 int __attribute__((cold))
640 ixgbe_rx_vec_dev_conf_condition_check(struct rte_eth_dev *dev)
641 {
642         return ixgbe_rx_vec_dev_conf_condition_check_default(dev);
643 }