net/ixgbe: add compile-time checks to vector driver
[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
86                 mb0 = rxep[0].mbuf;
87                 mb1 = rxep[1].mbuf;
88
89                 /* load buf_addr(lo 64bit) and buf_physaddr(hi 64bit) */
90                 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, buf_physaddr) !=
91                                 offsetof(struct rte_mbuf, buf_addr) + 8);
92                 vaddr0 = _mm_loadu_si128((__m128i *)&(mb0->buf_addr));
93                 vaddr1 = _mm_loadu_si128((__m128i *)&(mb1->buf_addr));
94
95                 /* convert pa to dma_addr hdr/data */
96                 dma_addr0 = _mm_unpackhi_epi64(vaddr0, vaddr0);
97                 dma_addr1 = _mm_unpackhi_epi64(vaddr1, vaddr1);
98
99                 /* add headroom to pa values */
100                 dma_addr0 = _mm_add_epi64(dma_addr0, hdr_room);
101                 dma_addr1 = _mm_add_epi64(dma_addr1, hdr_room);
102
103                 /* set Header Buffer Address to zero */
104                 dma_addr0 =  _mm_and_si128(dma_addr0, hba_msk);
105                 dma_addr1 =  _mm_and_si128(dma_addr1, hba_msk);
106
107                 /* flush desc with pa dma_addr */
108                 _mm_store_si128((__m128i *)&rxdp++->read, dma_addr0);
109                 _mm_store_si128((__m128i *)&rxdp++->read, dma_addr1);
110         }
111
112         rxq->rxrearm_start += RTE_IXGBE_RXQ_REARM_THRESH;
113         if (rxq->rxrearm_start >= rxq->nb_rx_desc)
114                 rxq->rxrearm_start = 0;
115
116         rxq->rxrearm_nb -= RTE_IXGBE_RXQ_REARM_THRESH;
117
118         rx_id = (uint16_t) ((rxq->rxrearm_start == 0) ?
119                              (rxq->nb_rx_desc - 1) : (rxq->rxrearm_start - 1));
120
121         /* Update the tail pointer on the NIC */
122         IXGBE_PCI_REG_WRITE(rxq->rdt_reg_addr, rx_id);
123 }
124
125 static inline void
126 desc_to_olflags_v(__m128i descs[4], __m128i mbuf_init, uint8_t vlan_flags,
127         struct rte_mbuf **rx_pkts)
128 {
129         __m128i ptype0, ptype1, vtag0, vtag1, csum;
130         __m128i rearm0, rearm1, rearm2, rearm3;
131
132         /* mask everything except rss type */
133         const __m128i rsstype_msk = _mm_set_epi16(
134                         0x0000, 0x0000, 0x0000, 0x0000,
135                         0x000F, 0x000F, 0x000F, 0x000F);
136
137         /* mask the lower byte of ol_flags */
138         const __m128i ol_flags_msk = _mm_set_epi16(
139                         0x0000, 0x0000, 0x0000, 0x0000,
140                         0x00FF, 0x00FF, 0x00FF, 0x00FF);
141
142         /* map rss type to rss hash flag */
143         const __m128i rss_flags = _mm_set_epi8(PKT_RX_FDIR, 0, 0, 0,
144                         0, 0, 0, PKT_RX_RSS_HASH,
145                         PKT_RX_RSS_HASH, 0, PKT_RX_RSS_HASH, 0,
146                         PKT_RX_RSS_HASH, PKT_RX_RSS_HASH, PKT_RX_RSS_HASH, 0);
147
148         /* mask everything except vlan present and l4/ip csum error */
149         const __m128i vlan_csum_msk = _mm_set_epi16(
150                 (IXGBE_RXDADV_ERR_TCPE | IXGBE_RXDADV_ERR_IPE) >> 16,
151                 (IXGBE_RXDADV_ERR_TCPE | IXGBE_RXDADV_ERR_IPE) >> 16,
152                 (IXGBE_RXDADV_ERR_TCPE | IXGBE_RXDADV_ERR_IPE) >> 16,
153                 (IXGBE_RXDADV_ERR_TCPE | IXGBE_RXDADV_ERR_IPE) >> 16,
154                 IXGBE_RXD_STAT_VP, IXGBE_RXD_STAT_VP,
155                 IXGBE_RXD_STAT_VP, IXGBE_RXD_STAT_VP);
156         /* map vlan present (0x8), IPE (0x2), L4E (0x1) to ol_flags */
157         const __m128i vlan_csum_map_lo = _mm_set_epi8(
158                 0, 0, 0, 0,
159                 vlan_flags | PKT_RX_IP_CKSUM_BAD | PKT_RX_L4_CKSUM_BAD,
160                 vlan_flags | PKT_RX_IP_CKSUM_BAD,
161                 vlan_flags | PKT_RX_IP_CKSUM_GOOD | PKT_RX_L4_CKSUM_BAD,
162                 vlan_flags | PKT_RX_IP_CKSUM_GOOD,
163                 0, 0, 0, 0,
164                 PKT_RX_IP_CKSUM_BAD | PKT_RX_L4_CKSUM_BAD,
165                 PKT_RX_IP_CKSUM_BAD,
166                 PKT_RX_IP_CKSUM_GOOD | PKT_RX_L4_CKSUM_BAD,
167                 PKT_RX_IP_CKSUM_GOOD);
168
169         const __m128i vlan_csum_map_hi = _mm_set_epi8(
170                 0, 0, 0, 0,
171                 0, PKT_RX_L4_CKSUM_GOOD >> sizeof(uint8_t), 0,
172                 PKT_RX_L4_CKSUM_GOOD >> sizeof(uint8_t),
173                 0, 0, 0, 0,
174                 0, PKT_RX_L4_CKSUM_GOOD >> sizeof(uint8_t), 0,
175                 PKT_RX_L4_CKSUM_GOOD >> sizeof(uint8_t));
176
177         ptype0 = _mm_unpacklo_epi16(descs[0], descs[1]);
178         ptype1 = _mm_unpacklo_epi16(descs[2], descs[3]);
179         vtag0 = _mm_unpackhi_epi16(descs[0], descs[1]);
180         vtag1 = _mm_unpackhi_epi16(descs[2], descs[3]);
181
182         ptype0 = _mm_unpacklo_epi32(ptype0, ptype1);
183         ptype0 = _mm_and_si128(ptype0, rsstype_msk);
184         ptype0 = _mm_shuffle_epi8(rss_flags, ptype0);
185
186         vtag1 = _mm_unpacklo_epi32(vtag0, vtag1);
187         vtag1 = _mm_and_si128(vtag1, vlan_csum_msk);
188
189         /* csum bits are in the most significant, to use shuffle we need to
190          * shift them. Change mask to 0xc000 to 0x0003.
191          */
192         csum = _mm_srli_epi16(vtag1, 14);
193
194         /* now or the most significant 64 bits containing the checksum
195          * flags with the vlan present flags.
196          */
197         csum = _mm_srli_si128(csum, 8);
198         vtag1 = _mm_or_si128(csum, vtag1);
199
200         /* convert VP, IPE, L4E to ol_flags */
201         vtag0 = _mm_shuffle_epi8(vlan_csum_map_hi, vtag1);
202         vtag0 = _mm_slli_epi16(vtag0, sizeof(uint8_t));
203
204         vtag1 = _mm_shuffle_epi8(vlan_csum_map_lo, vtag1);
205         vtag1 = _mm_and_si128(vtag1, ol_flags_msk);
206         vtag1 = _mm_or_si128(vtag0, vtag1);
207
208         vtag1 = _mm_or_si128(ptype0, vtag1);
209
210         /*
211          * At this point, we have the 4 sets of flags in the low 64-bits
212          * of vtag1 (4x16).
213          * We want to extract these, and merge them with the mbuf init data
214          * so we can do a single 16-byte write to the mbuf to set the flags
215          * and all the other initialization fields. Extracting the
216          * appropriate flags means that we have to do a shift and blend for
217          * each mbuf before we do the write.
218          */
219 #ifdef RTE_MACHINE_CPUFLAG_SSE4_2
220
221         rearm0 = _mm_blend_epi16(mbuf_init, _mm_slli_si128(vtag1, 8), 0x10);
222         rearm1 = _mm_blend_epi16(mbuf_init, _mm_slli_si128(vtag1, 6), 0x10);
223         rearm2 = _mm_blend_epi16(mbuf_init, _mm_slli_si128(vtag1, 4), 0x10);
224         rearm3 = _mm_blend_epi16(mbuf_init, _mm_slli_si128(vtag1, 2), 0x10);
225
226 #else
227         rearm0 = _mm_slli_si128(vtag1, 14);
228         rearm1 = _mm_slli_si128(vtag1, 12);
229         rearm2 = _mm_slli_si128(vtag1, 10);
230         rearm3 = _mm_slli_si128(vtag1, 8);
231
232         rearm0 = _mm_or_si128(mbuf_init, _mm_srli_epi64(rearm0, 48));
233         rearm1 = _mm_or_si128(mbuf_init, _mm_srli_epi64(rearm1, 48));
234         rearm2 = _mm_or_si128(mbuf_init, _mm_srli_epi64(rearm2, 48));
235         rearm3 = _mm_or_si128(mbuf_init, _mm_srli_epi64(rearm3, 48));
236
237 #endif /* RTE_MACHINE_CPUFLAG_SSE4_2 */
238
239         /* write the rearm data and the olflags in one write */
240         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, ol_flags) !=
241                         offsetof(struct rte_mbuf, rearm_data) + 8);
242         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, rearm_data) !=
243                         RTE_ALIGN(offsetof(struct rte_mbuf, rearm_data), 16));
244         _mm_store_si128((__m128i *)&rx_pkts[0]->rearm_data, rearm0);
245         _mm_store_si128((__m128i *)&rx_pkts[1]->rearm_data, rearm1);
246         _mm_store_si128((__m128i *)&rx_pkts[2]->rearm_data, rearm2);
247         _mm_store_si128((__m128i *)&rx_pkts[3]->rearm_data, rearm3);
248 }
249
250 /*
251  * vPMD raw receive routine, only accept(nb_pkts >= RTE_IXGBE_DESCS_PER_LOOP)
252  *
253  * Notice:
254  * - nb_pkts < RTE_IXGBE_DESCS_PER_LOOP, just return no packet
255  * - nb_pkts > RTE_IXGBE_MAX_RX_BURST, only scan RTE_IXGBE_MAX_RX_BURST
256  *   numbers of DD bit
257  * - floor align nb_pkts to a RTE_IXGBE_DESC_PER_LOOP power-of-two
258  */
259 static inline uint16_t
260 _recv_raw_pkts_vec(struct ixgbe_rx_queue *rxq, struct rte_mbuf **rx_pkts,
261                 uint16_t nb_pkts, uint8_t *split_packet)
262 {
263         volatile union ixgbe_adv_rx_desc *rxdp;
264         struct ixgbe_rx_entry *sw_ring;
265         uint16_t nb_pkts_recd;
266         int pos;
267         uint64_t var;
268         __m128i shuf_msk;
269         __m128i crc_adjust = _mm_set_epi16(
270                                 0, 0, 0,    /* ignore non-length fields */
271                                 -rxq->crc_len, /* sub crc on data_len */
272                                 0,          /* ignore high-16bits of pkt_len */
273                                 -rxq->crc_len, /* sub crc on pkt_len */
274                                 0, 0            /* ignore pkt_type field */
275                         );
276         /*
277          * compile-time check the above crc_adjust layout is correct.
278          * NOTE: the first field (lowest address) is given last in set_epi16
279          * call above.
280          */
281         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, pkt_len) !=
282                         offsetof(struct rte_mbuf, rx_descriptor_fields1) + 4);
283         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, data_len) !=
284                         offsetof(struct rte_mbuf, rx_descriptor_fields1) + 8);
285         __m128i dd_check, eop_check;
286         __m128i mbuf_init;
287         uint8_t vlan_flags;
288
289         /* nb_pkts shall be less equal than RTE_IXGBE_MAX_RX_BURST */
290         nb_pkts = RTE_MIN(nb_pkts, RTE_IXGBE_MAX_RX_BURST);
291
292         /* nb_pkts has to be floor-aligned to RTE_IXGBE_DESCS_PER_LOOP */
293         nb_pkts = RTE_ALIGN_FLOOR(nb_pkts, RTE_IXGBE_DESCS_PER_LOOP);
294
295         /* Just the act of getting into the function from the application is
296          * going to cost about 7 cycles
297          */
298         rxdp = rxq->rx_ring + rxq->rx_tail;
299
300         rte_prefetch0(rxdp);
301
302         /* See if we need to rearm the RX queue - gives the prefetch a bit
303          * of time to act
304          */
305         if (rxq->rxrearm_nb > RTE_IXGBE_RXQ_REARM_THRESH)
306                 ixgbe_rxq_rearm(rxq);
307
308         /* Before we start moving massive data around, check to see if
309          * there is actually a packet available
310          */
311         if (!(rxdp->wb.upper.status_error &
312                                 rte_cpu_to_le_32(IXGBE_RXDADV_STAT_DD)))
313                 return 0;
314
315         /* 4 packets DD mask */
316         dd_check = _mm_set_epi64x(0x0000000100000001LL, 0x0000000100000001LL);
317
318         /* 4 packets EOP mask */
319         eop_check = _mm_set_epi64x(0x0000000200000002LL, 0x0000000200000002LL);
320
321         /* mask to shuffle from desc. to mbuf */
322         shuf_msk = _mm_set_epi8(
323                 7, 6, 5, 4,  /* octet 4~7, 32bits rss */
324                 15, 14,      /* octet 14~15, low 16 bits vlan_macip */
325                 13, 12,      /* octet 12~13, 16 bits data_len */
326                 0xFF, 0xFF,  /* skip high 16 bits pkt_len, zero out */
327                 13, 12,      /* octet 12~13, low 16 bits pkt_len */
328                 0xFF, 0xFF,  /* skip 32 bit pkt_type */
329                 0xFF, 0xFF
330                 );
331         /*
332          * Compile-time verify the shuffle mask
333          * NOTE: some field positions already verified above, but duplicated
334          * here for completeness in case of future modifications.
335          */
336         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, pkt_len) !=
337                         offsetof(struct rte_mbuf, rx_descriptor_fields1) + 4);
338         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, data_len) !=
339                         offsetof(struct rte_mbuf, rx_descriptor_fields1) + 8);
340         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, vlan_tci) !=
341                         offsetof(struct rte_mbuf, rx_descriptor_fields1) + 10);
342         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, hash) !=
343                         offsetof(struct rte_mbuf, rx_descriptor_fields1) + 12);
344
345         mbuf_init = _mm_set_epi64x(0, rxq->mbuf_initializer);
346
347         /* Cache is empty -> need to scan the buffer rings, but first move
348          * the next 'n' mbufs into the cache
349          */
350         sw_ring = &rxq->sw_ring[rxq->rx_tail];
351
352         /* ensure these 2 flags are in the lower 8 bits */
353         RTE_BUILD_BUG_ON((PKT_RX_VLAN_PKT | PKT_RX_VLAN_STRIPPED) > UINT8_MAX);
354         vlan_flags = rxq->vlan_flags & UINT8_MAX;
355
356         /* A. load 4 packet in one loop
357          * [A*. mask out 4 unused dirty field in desc]
358          * B. copy 4 mbuf point from swring to rx_pkts
359          * C. calc the number of DD bits among the 4 packets
360          * [C*. extract the end-of-packet bit, if requested]
361          * D. fill info. from desc to mbuf
362          */
363         for (pos = 0, nb_pkts_recd = 0; pos < nb_pkts;
364                         pos += RTE_IXGBE_DESCS_PER_LOOP,
365                         rxdp += RTE_IXGBE_DESCS_PER_LOOP) {
366                 __m128i descs[RTE_IXGBE_DESCS_PER_LOOP];
367                 __m128i pkt_mb1, pkt_mb2, pkt_mb3, pkt_mb4;
368                 __m128i zero, staterr, sterr_tmp1, sterr_tmp2;
369                 /* 2 64 bit or 4 32 bit mbuf pointers in one XMM reg. */
370                 __m128i mbp1;
371 #if defined(RTE_ARCH_X86_64)
372                 __m128i mbp2;
373 #endif
374
375                 /* B.1 load 2 (64 bit) or 4 (32 bit) mbuf points */
376                 mbp1 = _mm_loadu_si128((__m128i *)&sw_ring[pos]);
377
378                 /* Read desc statuses backwards to avoid race condition */
379                 /* A.1 load 4 pkts desc */
380                 descs[3] = _mm_loadu_si128((__m128i *)(rxdp + 3));
381                 rte_compiler_barrier();
382
383                 /* B.2 copy 2 64 bit or 4 32 bit mbuf point into rx_pkts */
384                 _mm_storeu_si128((__m128i *)&rx_pkts[pos], mbp1);
385
386 #if defined(RTE_ARCH_X86_64)
387                 /* B.1 load 2 64 bit mbuf points */
388                 mbp2 = _mm_loadu_si128((__m128i *)&sw_ring[pos+2]);
389 #endif
390
391                 descs[2] = _mm_loadu_si128((__m128i *)(rxdp + 2));
392                 rte_compiler_barrier();
393                 /* B.1 load 2 mbuf point */
394                 descs[1] = _mm_loadu_si128((__m128i *)(rxdp + 1));
395                 rte_compiler_barrier();
396                 descs[0] = _mm_loadu_si128((__m128i *)(rxdp));
397
398 #if defined(RTE_ARCH_X86_64)
399                 /* B.2 copy 2 mbuf point into rx_pkts  */
400                 _mm_storeu_si128((__m128i *)&rx_pkts[pos+2], mbp2);
401 #endif
402
403                 if (split_packet) {
404                         rte_mbuf_prefetch_part2(rx_pkts[pos]);
405                         rte_mbuf_prefetch_part2(rx_pkts[pos + 1]);
406                         rte_mbuf_prefetch_part2(rx_pkts[pos + 2]);
407                         rte_mbuf_prefetch_part2(rx_pkts[pos + 3]);
408                 }
409
410                 /* avoid compiler reorder optimization */
411                 rte_compiler_barrier();
412
413                 /* D.1 pkt 3,4 convert format from desc to pktmbuf */
414                 pkt_mb4 = _mm_shuffle_epi8(descs[3], shuf_msk);
415                 pkt_mb3 = _mm_shuffle_epi8(descs[2], shuf_msk);
416
417                 /* D.1 pkt 1,2 convert format from desc to pktmbuf */
418                 pkt_mb2 = _mm_shuffle_epi8(descs[1], shuf_msk);
419                 pkt_mb1 = _mm_shuffle_epi8(descs[0], shuf_msk);
420
421                 /* C.1 4=>2 filter staterr info only */
422                 sterr_tmp2 = _mm_unpackhi_epi32(descs[3], descs[2]);
423                 /* C.1 4=>2 filter staterr info only */
424                 sterr_tmp1 = _mm_unpackhi_epi32(descs[1], descs[0]);
425
426                 /* set ol_flags with vlan packet type */
427                 desc_to_olflags_v(descs, mbuf_init, vlan_flags, &rx_pkts[pos]);
428
429                 /* D.2 pkt 3,4 set in_port/nb_seg and remove crc */
430                 pkt_mb4 = _mm_add_epi16(pkt_mb4, crc_adjust);
431                 pkt_mb3 = _mm_add_epi16(pkt_mb3, crc_adjust);
432
433                 /* C.2 get 4 pkts staterr value  */
434                 zero = _mm_xor_si128(dd_check, dd_check);
435                 staterr = _mm_unpacklo_epi32(sterr_tmp1, sterr_tmp2);
436
437                 /* D.3 copy final 3,4 data to rx_pkts */
438                 _mm_storeu_si128((void *)&rx_pkts[pos+3]->rx_descriptor_fields1,
439                                 pkt_mb4);
440                 _mm_storeu_si128((void *)&rx_pkts[pos+2]->rx_descriptor_fields1,
441                                 pkt_mb3);
442
443                 /* D.2 pkt 1,2 set in_port/nb_seg and remove crc */
444                 pkt_mb2 = _mm_add_epi16(pkt_mb2, crc_adjust);
445                 pkt_mb1 = _mm_add_epi16(pkt_mb1, crc_adjust);
446
447                 /* C* extract and record EOP bit */
448                 if (split_packet) {
449                         __m128i eop_shuf_mask = _mm_set_epi8(
450                                         0xFF, 0xFF, 0xFF, 0xFF,
451                                         0xFF, 0xFF, 0xFF, 0xFF,
452                                         0xFF, 0xFF, 0xFF, 0xFF,
453                                         0x04, 0x0C, 0x00, 0x08
454                                         );
455
456                         /* and with mask to extract bits, flipping 1-0 */
457                         __m128i eop_bits = _mm_andnot_si128(staterr, eop_check);
458                         /* the staterr values are not in order, as the count
459                          * count of dd bits doesn't care. However, for end of
460                          * packet tracking, we do care, so shuffle. This also
461                          * compresses the 32-bit values to 8-bit
462                          */
463                         eop_bits = _mm_shuffle_epi8(eop_bits, eop_shuf_mask);
464                         /* store the resulting 32-bit value */
465                         *(int *)split_packet = _mm_cvtsi128_si32(eop_bits);
466                         split_packet += RTE_IXGBE_DESCS_PER_LOOP;
467                 }
468
469                 /* C.3 calc available number of desc */
470                 staterr = _mm_and_si128(staterr, dd_check);
471                 staterr = _mm_packs_epi32(staterr, zero);
472
473                 /* D.3 copy final 1,2 data to rx_pkts */
474                 _mm_storeu_si128((void *)&rx_pkts[pos+1]->rx_descriptor_fields1,
475                                 pkt_mb2);
476                 _mm_storeu_si128((void *)&rx_pkts[pos]->rx_descriptor_fields1,
477                                 pkt_mb1);
478
479                 /* C.4 calc avaialbe number of desc */
480                 var = __builtin_popcountll(_mm_cvtsi128_si64(staterr));
481                 nb_pkts_recd += var;
482                 if (likely(var != RTE_IXGBE_DESCS_PER_LOOP))
483                         break;
484         }
485
486         /* Update our internal tail pointer */
487         rxq->rx_tail = (uint16_t)(rxq->rx_tail + nb_pkts_recd);
488         rxq->rx_tail = (uint16_t)(rxq->rx_tail & (rxq->nb_rx_desc - 1));
489         rxq->rxrearm_nb = (uint16_t)(rxq->rxrearm_nb + nb_pkts_recd);
490
491         return nb_pkts_recd;
492 }
493
494 /*
495  * vPMD receive routine, only accept(nb_pkts >= RTE_IXGBE_DESCS_PER_LOOP)
496  *
497  * Notice:
498  * - nb_pkts < RTE_IXGBE_DESCS_PER_LOOP, just return no packet
499  * - nb_pkts > RTE_IXGBE_MAX_RX_BURST, only scan RTE_IXGBE_MAX_RX_BURST
500  *   numbers of DD bit
501  * - floor align nb_pkts to a RTE_IXGBE_DESC_PER_LOOP power-of-two
502  */
503 uint16_t
504 ixgbe_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
505                 uint16_t nb_pkts)
506 {
507         return _recv_raw_pkts_vec(rx_queue, rx_pkts, nb_pkts, NULL);
508 }
509
510 /*
511  * vPMD receive routine that reassembles scattered packets
512  *
513  * Notice:
514  * - nb_pkts < RTE_IXGBE_DESCS_PER_LOOP, just return no packet
515  * - nb_pkts > RTE_IXGBE_MAX_RX_BURST, only scan RTE_IXGBE_MAX_RX_BURST
516  *   numbers of DD bit
517  * - floor align nb_pkts to a RTE_IXGBE_DESC_PER_LOOP power-of-two
518  */
519 uint16_t
520 ixgbe_recv_scattered_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
521                 uint16_t nb_pkts)
522 {
523         struct ixgbe_rx_queue *rxq = rx_queue;
524         uint8_t split_flags[RTE_IXGBE_MAX_RX_BURST] = {0};
525
526         /* get some new buffers */
527         uint16_t nb_bufs = _recv_raw_pkts_vec(rxq, rx_pkts, nb_pkts,
528                         split_flags);
529         if (nb_bufs == 0)
530                 return 0;
531
532         /* happy day case, full burst + no packets to be joined */
533         const uint64_t *split_fl64 = (uint64_t *)split_flags;
534         if (rxq->pkt_first_seg == NULL &&
535                         split_fl64[0] == 0 && split_fl64[1] == 0 &&
536                         split_fl64[2] == 0 && split_fl64[3] == 0)
537                 return nb_bufs;
538
539         /* reassemble any packets that need reassembly*/
540         unsigned i = 0;
541         if (rxq->pkt_first_seg == NULL) {
542                 /* find the first split flag, and only reassemble then*/
543                 while (i < nb_bufs && !split_flags[i])
544                         i++;
545                 if (i == nb_bufs)
546                         return nb_bufs;
547         }
548         return i + reassemble_packets(rxq, &rx_pkts[i], nb_bufs - i,
549                 &split_flags[i]);
550 }
551
552 static inline void
553 vtx1(volatile union ixgbe_adv_tx_desc *txdp,
554                 struct rte_mbuf *pkt, uint64_t flags)
555 {
556         __m128i descriptor = _mm_set_epi64x((uint64_t)pkt->pkt_len << 46 |
557                         flags | pkt->data_len,
558                         pkt->buf_physaddr + pkt->data_off);
559         _mm_store_si128((__m128i *)&txdp->read, descriptor);
560 }
561
562 static inline void
563 vtx(volatile union ixgbe_adv_tx_desc *txdp,
564                 struct rte_mbuf **pkt, uint16_t nb_pkts,  uint64_t flags)
565 {
566         int i;
567
568         for (i = 0; i < nb_pkts; ++i, ++txdp, ++pkt)
569                 vtx1(txdp, *pkt, flags);
570 }
571
572 uint16_t
573 ixgbe_xmit_fixed_burst_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
574                            uint16_t nb_pkts)
575 {
576         struct ixgbe_tx_queue *txq = (struct ixgbe_tx_queue *)tx_queue;
577         volatile union ixgbe_adv_tx_desc *txdp;
578         struct ixgbe_tx_entry_v *txep;
579         uint16_t n, nb_commit, tx_id;
580         uint64_t flags = DCMD_DTYP_FLAGS;
581         uint64_t rs = IXGBE_ADVTXD_DCMD_RS|DCMD_DTYP_FLAGS;
582         int i;
583
584         /* cross rx_thresh boundary is not allowed */
585         nb_pkts = RTE_MIN(nb_pkts, txq->tx_rs_thresh);
586
587         if (txq->nb_tx_free < txq->tx_free_thresh)
588                 ixgbe_tx_free_bufs(txq);
589
590         nb_commit = nb_pkts = (uint16_t)RTE_MIN(txq->nb_tx_free, nb_pkts);
591         if (unlikely(nb_pkts == 0))
592                 return 0;
593
594         tx_id = txq->tx_tail;
595         txdp = &txq->tx_ring[tx_id];
596         txep = &txq->sw_ring_v[tx_id];
597
598         txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_pkts);
599
600         n = (uint16_t)(txq->nb_tx_desc - tx_id);
601         if (nb_commit >= n) {
602
603                 tx_backlog_entry(txep, tx_pkts, n);
604
605                 for (i = 0; i < n - 1; ++i, ++tx_pkts, ++txdp)
606                         vtx1(txdp, *tx_pkts, flags);
607
608                 vtx1(txdp, *tx_pkts++, rs);
609
610                 nb_commit = (uint16_t)(nb_commit - n);
611
612                 tx_id = 0;
613                 txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
614
615                 /* avoid reach the end of ring */
616                 txdp = &(txq->tx_ring[tx_id]);
617                 txep = &txq->sw_ring_v[tx_id];
618         }
619
620         tx_backlog_entry(txep, tx_pkts, nb_commit);
621
622         vtx(txdp, tx_pkts, nb_commit, flags);
623
624         tx_id = (uint16_t)(tx_id + nb_commit);
625         if (tx_id > txq->tx_next_rs) {
626                 txq->tx_ring[txq->tx_next_rs].read.cmd_type_len |=
627                         rte_cpu_to_le_32(IXGBE_ADVTXD_DCMD_RS);
628                 txq->tx_next_rs = (uint16_t)(txq->tx_next_rs +
629                         txq->tx_rs_thresh);
630         }
631
632         txq->tx_tail = tx_id;
633
634         IXGBE_PCI_REG_WRITE(txq->tdt_reg_addr, txq->tx_tail);
635
636         return nb_pkts;
637 }
638
639 static void __attribute__((cold))
640 ixgbe_tx_queue_release_mbufs_vec(struct ixgbe_tx_queue *txq)
641 {
642         _ixgbe_tx_queue_release_mbufs_vec(txq);
643 }
644
645 void __attribute__((cold))
646 ixgbe_rx_queue_release_mbufs_vec(struct ixgbe_rx_queue *rxq)
647 {
648         _ixgbe_rx_queue_release_mbufs_vec(rxq);
649 }
650
651 static void __attribute__((cold))
652 ixgbe_tx_free_swring(struct ixgbe_tx_queue *txq)
653 {
654         _ixgbe_tx_free_swring_vec(txq);
655 }
656
657 static void __attribute__((cold))
658 ixgbe_reset_tx_queue(struct ixgbe_tx_queue *txq)
659 {
660         _ixgbe_reset_tx_queue_vec(txq);
661 }
662
663 static const struct ixgbe_txq_ops vec_txq_ops = {
664         .release_mbufs = ixgbe_tx_queue_release_mbufs_vec,
665         .free_swring = ixgbe_tx_free_swring,
666         .reset = ixgbe_reset_tx_queue,
667 };
668
669 int __attribute__((cold))
670 ixgbe_rxq_vec_setup(struct ixgbe_rx_queue *rxq)
671 {
672         return ixgbe_rxq_vec_setup_default(rxq);
673 }
674
675 int __attribute__((cold))
676 ixgbe_txq_vec_setup(struct ixgbe_tx_queue *txq)
677 {
678         return ixgbe_txq_vec_setup_default(txq, &vec_txq_ops);
679 }
680
681 int __attribute__((cold))
682 ixgbe_rx_vec_dev_conf_condition_check(struct rte_eth_dev *dev)
683 {
684         return ixgbe_rx_vec_dev_conf_condition_check_default(dev);
685 }