4 * Copyright(c) 2013-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.
36 #include <rte_ethdev.h>
37 #include <rte_common.h>
39 #include "base/fm10k_type.h"
41 #include <tmmintrin.h>
43 #ifndef __INTEL_COMPILER
44 #pragma GCC diagnostic ignored "-Wcast-qual"
48 fm10k_reset_tx_queue(struct fm10k_tx_queue *txq);
50 /* Handling the offload flags (olflags) field takes computation
51 * time when receiving packets. Therefore we provide a flag to disable
52 * the processing of the olflags field when they are not needed. This
53 * gives improved performance, at the cost of losing the offload info
54 * in the received packet
56 #ifdef RTE_LIBRTE_FM10K_RX_OLFLAGS_ENABLE
58 /* Vlan present flag shift */
61 #define L3TYPE_SHIFT (4)
63 #define L4TYPE_SHIFT (7)
65 #define HBOFLAG_SHIFT (10)
67 #define RXEFLAG_SHIFT (13)
68 /* IPE/L4E flag shift */
69 #define L3L4EFLAG_SHIFT (14)
72 fm10k_desc_to_olflags_v(__m128i descs[4], struct rte_mbuf **rx_pkts)
74 __m128i ptype0, ptype1, vtag0, vtag1, eflag0, eflag1, cksumflag;
80 const __m128i pkttype_msk = _mm_set_epi16(
81 0x0000, 0x0000, 0x0000, 0x0000,
82 PKT_RX_VLAN_PKT, PKT_RX_VLAN_PKT,
83 PKT_RX_VLAN_PKT, PKT_RX_VLAN_PKT);
85 /* mask everything except rss type */
86 const __m128i rsstype_msk = _mm_set_epi16(
87 0x0000, 0x0000, 0x0000, 0x0000,
88 0x000F, 0x000F, 0x000F, 0x000F);
90 /* mask for HBO and RXE flag flags */
91 const __m128i rxe_msk = _mm_set_epi16(
92 0x0000, 0x0000, 0x0000, 0x0000,
93 0x0001, 0x0001, 0x0001, 0x0001);
95 const __m128i l3l4cksum_flag = _mm_set_epi8(0, 0, 0, 0,
98 PKT_RX_IP_CKSUM_BAD | PKT_RX_L4_CKSUM_BAD,
99 PKT_RX_IP_CKSUM_BAD, PKT_RX_L4_CKSUM_BAD, 0);
101 const __m128i rxe_flag = _mm_set_epi8(0, 0, 0, 0,
106 /* map rss type to rss hash flag */
107 const __m128i rss_flags = _mm_set_epi8(0, 0, 0, 0,
108 0, 0, 0, PKT_RX_RSS_HASH,
109 PKT_RX_RSS_HASH, 0, PKT_RX_RSS_HASH, 0,
110 PKT_RX_RSS_HASH, PKT_RX_RSS_HASH, PKT_RX_RSS_HASH, 0);
112 /* Calculate RSS_hash and Vlan fields */
113 ptype0 = _mm_unpacklo_epi16(descs[0], descs[1]);
114 ptype1 = _mm_unpacklo_epi16(descs[2], descs[3]);
115 vtag0 = _mm_unpackhi_epi16(descs[0], descs[1]);
116 vtag1 = _mm_unpackhi_epi16(descs[2], descs[3]);
118 ptype0 = _mm_unpacklo_epi32(ptype0, ptype1);
119 ptype0 = _mm_and_si128(ptype0, rsstype_msk);
120 ptype0 = _mm_shuffle_epi8(rss_flags, ptype0);
122 vtag1 = _mm_unpacklo_epi32(vtag0, vtag1);
125 vtag1 = _mm_srli_epi16(vtag1, VP_SHIFT);
126 vtag1 = _mm_and_si128(vtag1, pkttype_msk);
128 vtag1 = _mm_or_si128(ptype0, vtag1);
130 /* Process err flags, simply set RECIP_ERR bit if HBO/IXE is set */
131 eflag1 = _mm_srli_epi16(eflag0, RXEFLAG_SHIFT);
132 eflag0 = _mm_srli_epi16(eflag0, HBOFLAG_SHIFT);
133 eflag0 = _mm_or_si128(eflag0, eflag1);
134 eflag0 = _mm_and_si128(eflag0, rxe_msk);
135 eflag0 = _mm_shuffle_epi8(rxe_flag, eflag0);
137 vtag1 = _mm_or_si128(eflag0, vtag1);
139 /* Process L4/L3 checksum error flags */
140 cksumflag = _mm_srli_epi16(cksumflag, L3L4EFLAG_SHIFT);
141 cksumflag = _mm_shuffle_epi8(l3l4cksum_flag, cksumflag);
142 vtag1 = _mm_or_si128(cksumflag, vtag1);
144 vol.dword = _mm_cvtsi128_si64(vtag1);
146 rx_pkts[0]->ol_flags = vol.e[0];
147 rx_pkts[1]->ol_flags = vol.e[1];
148 rx_pkts[2]->ol_flags = vol.e[2];
149 rx_pkts[3]->ol_flags = vol.e[3];
152 /* @note: When this function is changed, make corresponding change to
153 * fm10k_dev_supported_ptypes_get().
156 fm10k_desc_to_pktype_v(__m128i descs[4], struct rte_mbuf **rx_pkts)
158 __m128i l3l4type0, l3l4type1, l3type, l4type;
164 /* L3 pkt type mask Bit4 to Bit6 */
165 const __m128i l3type_msk = _mm_set_epi16(
166 0x0000, 0x0000, 0x0000, 0x0000,
167 0x0070, 0x0070, 0x0070, 0x0070);
169 /* L4 pkt type mask Bit7 to Bit9 */
170 const __m128i l4type_msk = _mm_set_epi16(
171 0x0000, 0x0000, 0x0000, 0x0000,
172 0x0380, 0x0380, 0x0380, 0x0380);
174 /* convert RRC l3 type to mbuf format */
175 const __m128i l3type_flags = _mm_set_epi8(0, 0, 0, 0, 0, 0, 0, 0,
176 0, 0, 0, RTE_PTYPE_L3_IPV6_EXT,
177 RTE_PTYPE_L3_IPV6, RTE_PTYPE_L3_IPV4_EXT,
178 RTE_PTYPE_L3_IPV4, 0);
180 /* Convert RRC l4 type to mbuf format l4type_flags shift-left 8 bits
181 * to fill into8 bits length.
183 const __m128i l4type_flags = _mm_set_epi8(0, 0, 0, 0, 0, 0, 0, 0, 0,
184 RTE_PTYPE_TUNNEL_GENEVE >> 8,
185 RTE_PTYPE_TUNNEL_NVGRE >> 8,
186 RTE_PTYPE_TUNNEL_VXLAN >> 8,
187 RTE_PTYPE_TUNNEL_GRE >> 8,
188 RTE_PTYPE_L4_UDP >> 8,
189 RTE_PTYPE_L4_TCP >> 8,
192 l3l4type0 = _mm_unpacklo_epi16(descs[0], descs[1]);
193 l3l4type1 = _mm_unpacklo_epi16(descs[2], descs[3]);
194 l3l4type0 = _mm_unpacklo_epi32(l3l4type0, l3l4type1);
196 l3type = _mm_and_si128(l3l4type0, l3type_msk);
197 l4type = _mm_and_si128(l3l4type0, l4type_msk);
199 l3type = _mm_srli_epi16(l3type, L3TYPE_SHIFT);
200 l4type = _mm_srli_epi16(l4type, L4TYPE_SHIFT);
202 l3type = _mm_shuffle_epi8(l3type_flags, l3type);
203 /* l4type_flags shift-left for 8 bits, need shift-right back */
204 l4type = _mm_shuffle_epi8(l4type_flags, l4type);
206 l4type = _mm_slli_epi16(l4type, 8);
207 l3l4type0 = _mm_or_si128(l3type, l4type);
208 vol.dword = _mm_cvtsi128_si64(l3l4type0);
210 rx_pkts[0]->packet_type = vol.e[0];
211 rx_pkts[1]->packet_type = vol.e[1];
212 rx_pkts[2]->packet_type = vol.e[2];
213 rx_pkts[3]->packet_type = vol.e[3];
216 #define fm10k_desc_to_olflags_v(desc, rx_pkts) do {} while (0)
217 #define fm10k_desc_to_pktype_v(desc, rx_pkts) do {} while (0)
220 int __attribute__((cold))
221 fm10k_rx_vec_condition_check(struct rte_eth_dev *dev)
223 #ifndef RTE_LIBRTE_IEEE1588
224 struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
225 struct rte_fdir_conf *fconf = &dev->data->dev_conf.fdir_conf;
227 #ifndef RTE_FM10K_RX_OLFLAGS_ENABLE
228 /* whithout rx ol_flags, no VP flag report */
229 if (rxmode->hw_vlan_extend != 0)
233 /* no fdir support */
234 if (fconf->mode != RTE_FDIR_MODE_NONE)
237 /* - no csum error report support
238 * - no header split support
240 if (rxmode->hw_ip_checksum == 1 ||
241 rxmode->header_split == 1)
251 int __attribute__((cold))
252 fm10k_rxq_vec_setup(struct fm10k_rx_queue *rxq)
255 struct rte_mbuf mb_def = { .buf_addr = 0 }; /* zeroed mbuf */
258 /* data_off will be ajusted after new mbuf allocated for 512-byte
261 mb_def.data_off = RTE_PKTMBUF_HEADROOM;
262 mb_def.port = rxq->port_id;
263 rte_mbuf_refcnt_set(&mb_def, 1);
265 /* prevent compiler reordering: rearm_data covers previous fields */
266 rte_compiler_barrier();
267 p = (uintptr_t)&mb_def.rearm_data;
268 rxq->mbuf_initializer = *(uint64_t *)p;
273 fm10k_rxq_rearm(struct fm10k_rx_queue *rxq)
277 volatile union fm10k_rx_desc *rxdp;
278 struct rte_mbuf **mb_alloc = &rxq->sw_ring[rxq->rxrearm_start];
279 struct rte_mbuf *mb0, *mb1;
280 __m128i head_off = _mm_set_epi64x(
281 RTE_PKTMBUF_HEADROOM + FM10K_RX_DATABUF_ALIGN - 1,
282 RTE_PKTMBUF_HEADROOM + FM10K_RX_DATABUF_ALIGN - 1);
283 __m128i dma_addr0, dma_addr1;
284 /* Rx buffer need to be aligned with 512 byte */
285 const __m128i hba_msk = _mm_set_epi64x(0,
286 UINT64_MAX - FM10K_RX_DATABUF_ALIGN + 1);
288 rxdp = rxq->hw_ring + rxq->rxrearm_start;
290 /* Pull 'n' more MBUFs into the software ring */
291 if (rte_mempool_get_bulk(rxq->mp,
293 RTE_FM10K_RXQ_REARM_THRESH) < 0) {
294 dma_addr0 = _mm_setzero_si128();
295 /* Clean up all the HW/SW ring content */
296 for (i = 0; i < RTE_FM10K_RXQ_REARM_THRESH; i++) {
297 mb_alloc[i] = &rxq->fake_mbuf;
298 _mm_store_si128((__m128i *)&rxdp[i].q,
302 rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed +=
303 RTE_FM10K_RXQ_REARM_THRESH;
307 /* Initialize the mbufs in vector, process 2 mbufs in one loop */
308 for (i = 0; i < RTE_FM10K_RXQ_REARM_THRESH; i += 2, mb_alloc += 2) {
309 __m128i vaddr0, vaddr1;
315 /* Flush mbuf with pkt template.
316 * Data to be rearmed is 6 bytes long.
317 * Though, RX will overwrite ol_flags that are coming next
318 * anyway. So overwrite whole 8 bytes with one load:
319 * 6 bytes of rearm_data plus first 2 bytes of ol_flags.
321 p0 = (uintptr_t)&mb0->rearm_data;
322 *(uint64_t *)p0 = rxq->mbuf_initializer;
323 p1 = (uintptr_t)&mb1->rearm_data;
324 *(uint64_t *)p1 = rxq->mbuf_initializer;
326 /* load buf_addr(lo 64bit) and buf_physaddr(hi 64bit) */
327 vaddr0 = _mm_loadu_si128((__m128i *)&mb0->buf_addr);
328 vaddr1 = _mm_loadu_si128((__m128i *)&mb1->buf_addr);
330 /* convert pa to dma_addr hdr/data */
331 dma_addr0 = _mm_unpackhi_epi64(vaddr0, vaddr0);
332 dma_addr1 = _mm_unpackhi_epi64(vaddr1, vaddr1);
334 /* add headroom to pa values */
335 dma_addr0 = _mm_add_epi64(dma_addr0, head_off);
336 dma_addr1 = _mm_add_epi64(dma_addr1, head_off);
338 /* Do 512 byte alignment to satisfy HW requirement, in the
339 * meanwhile, set Header Buffer Address to zero.
341 dma_addr0 = _mm_and_si128(dma_addr0, hba_msk);
342 dma_addr1 = _mm_and_si128(dma_addr1, hba_msk);
344 /* flush desc with pa dma_addr */
345 _mm_store_si128((__m128i *)&rxdp++->q, dma_addr0);
346 _mm_store_si128((__m128i *)&rxdp++->q, dma_addr1);
348 /* enforce 512B alignment on default Rx virtual addresses */
349 mb0->data_off = (uint16_t)(RTE_PTR_ALIGN((char *)mb0->buf_addr
350 + RTE_PKTMBUF_HEADROOM, FM10K_RX_DATABUF_ALIGN)
351 - (char *)mb0->buf_addr);
352 mb1->data_off = (uint16_t)(RTE_PTR_ALIGN((char *)mb1->buf_addr
353 + RTE_PKTMBUF_HEADROOM, FM10K_RX_DATABUF_ALIGN)
354 - (char *)mb1->buf_addr);
357 rxq->rxrearm_start += RTE_FM10K_RXQ_REARM_THRESH;
358 if (rxq->rxrearm_start >= rxq->nb_desc)
359 rxq->rxrearm_start = 0;
361 rxq->rxrearm_nb -= RTE_FM10K_RXQ_REARM_THRESH;
363 rx_id = (uint16_t)((rxq->rxrearm_start == 0) ?
364 (rxq->nb_desc - 1) : (rxq->rxrearm_start - 1));
366 /* Update the tail pointer on the NIC */
367 FM10K_PCI_REG_WRITE(rxq->tail_ptr, rx_id);
370 void __attribute__((cold))
371 fm10k_rx_queue_release_mbufs_vec(struct fm10k_rx_queue *rxq)
373 const unsigned mask = rxq->nb_desc - 1;
376 if (rxq->sw_ring == NULL || rxq->rxrearm_nb >= rxq->nb_desc)
379 /* free all mbufs that are valid in the ring */
380 for (i = rxq->next_dd; i != rxq->rxrearm_start; i = (i + 1) & mask)
381 rte_pktmbuf_free_seg(rxq->sw_ring[i]);
382 rxq->rxrearm_nb = rxq->nb_desc;
384 /* set all entries to NULL */
385 memset(rxq->sw_ring, 0, sizeof(rxq->sw_ring[0]) * rxq->nb_desc);
388 static inline uint16_t
389 fm10k_recv_raw_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
390 uint16_t nb_pkts, uint8_t *split_packet)
392 volatile union fm10k_rx_desc *rxdp;
393 struct rte_mbuf **mbufp;
394 uint16_t nb_pkts_recd;
396 struct fm10k_rx_queue *rxq = rx_queue;
399 __m128i dd_check, eop_check;
402 next_dd = rxq->next_dd;
404 /* Just the act of getting into the function from the application is
405 * going to cost about 7 cycles
407 rxdp = rxq->hw_ring + next_dd;
411 /* See if we need to rearm the RX queue - gives the prefetch a bit
414 if (rxq->rxrearm_nb > RTE_FM10K_RXQ_REARM_THRESH)
415 fm10k_rxq_rearm(rxq);
417 /* Before we start moving massive data around, check to see if
418 * there is actually a packet available
420 if (!(rxdp->d.staterr & FM10K_RXD_STATUS_DD))
423 /* Vecotr RX will process 4 packets at a time, strip the unaligned
424 * tails in case it's not multiple of 4.
426 nb_pkts = RTE_ALIGN_FLOOR(nb_pkts, RTE_FM10K_DESCS_PER_LOOP);
428 /* 4 packets DD mask */
429 dd_check = _mm_set_epi64x(0x0000000100000001LL, 0x0000000100000001LL);
431 /* 4 packets EOP mask */
432 eop_check = _mm_set_epi64x(0x0000000200000002LL, 0x0000000200000002LL);
434 /* mask to shuffle from desc. to mbuf */
435 shuf_msk = _mm_set_epi8(
436 7, 6, 5, 4, /* octet 4~7, 32bits rss */
437 15, 14, /* octet 14~15, low 16 bits vlan_macip */
438 13, 12, /* octet 12~13, 16 bits data_len */
439 0xFF, 0xFF, /* skip high 16 bits pkt_len, zero out */
440 13, 12, /* octet 12~13, low 16 bits pkt_len */
441 0xFF, 0xFF, /* skip high 16 bits pkt_type */
442 0xFF, 0xFF /* Skip pkt_type field in shuffle operation */
445 /* Cache is empty -> need to scan the buffer rings, but first move
446 * the next 'n' mbufs into the cache
448 mbufp = &rxq->sw_ring[next_dd];
450 /* A. load 4 packet in one loop
451 * [A*. mask out 4 unused dirty field in desc]
452 * B. copy 4 mbuf point from swring to rx_pkts
453 * C. calc the number of DD bits among the 4 packets
454 * [C*. extract the end-of-packet bit, if requested]
455 * D. fill info. from desc to mbuf
457 for (pos = 0, nb_pkts_recd = 0; pos < nb_pkts;
458 pos += RTE_FM10K_DESCS_PER_LOOP,
459 rxdp += RTE_FM10K_DESCS_PER_LOOP) {
460 __m128i descs0[RTE_FM10K_DESCS_PER_LOOP];
461 __m128i pkt_mb1, pkt_mb2, pkt_mb3, pkt_mb4;
462 __m128i zero, staterr, sterr_tmp1, sterr_tmp2;
463 __m128i mbp1, mbp2; /* two mbuf pointer in one XMM reg. */
465 /* B.1 load 1 mbuf point */
466 mbp1 = _mm_loadu_si128((__m128i *)&mbufp[pos]);
468 /* Read desc statuses backwards to avoid race condition */
469 /* A.1 load 4 pkts desc */
470 descs0[3] = _mm_loadu_si128((__m128i *)(rxdp + 3));
472 /* B.2 copy 2 mbuf point into rx_pkts */
473 _mm_storeu_si128((__m128i *)&rx_pkts[pos], mbp1);
475 /* B.1 load 1 mbuf point */
476 mbp2 = _mm_loadu_si128((__m128i *)&mbufp[pos+2]);
478 descs0[2] = _mm_loadu_si128((__m128i *)(rxdp + 2));
479 /* B.1 load 2 mbuf point */
480 descs0[1] = _mm_loadu_si128((__m128i *)(rxdp + 1));
481 descs0[0] = _mm_loadu_si128((__m128i *)(rxdp));
483 /* B.2 copy 2 mbuf point into rx_pkts */
484 _mm_storeu_si128((__m128i *)&rx_pkts[pos+2], mbp2);
486 /* avoid compiler reorder optimization */
487 rte_compiler_barrier();
490 rte_mbuf_prefetch_part2(rx_pkts[pos]);
491 rte_mbuf_prefetch_part2(rx_pkts[pos + 1]);
492 rte_mbuf_prefetch_part2(rx_pkts[pos + 2]);
493 rte_mbuf_prefetch_part2(rx_pkts[pos + 3]);
496 /* D.1 pkt 3,4 convert format from desc to pktmbuf */
497 pkt_mb4 = _mm_shuffle_epi8(descs0[3], shuf_msk);
498 pkt_mb3 = _mm_shuffle_epi8(descs0[2], shuf_msk);
500 /* C.1 4=>2 filter staterr info only */
501 sterr_tmp2 = _mm_unpackhi_epi32(descs0[3], descs0[2]);
502 /* C.1 4=>2 filter staterr info only */
503 sterr_tmp1 = _mm_unpackhi_epi32(descs0[1], descs0[0]);
505 /* set ol_flags with vlan packet type */
506 fm10k_desc_to_olflags_v(descs0, &rx_pkts[pos]);
508 /* D.1 pkt 1,2 convert format from desc to pktmbuf */
509 pkt_mb2 = _mm_shuffle_epi8(descs0[1], shuf_msk);
510 pkt_mb1 = _mm_shuffle_epi8(descs0[0], shuf_msk);
512 /* C.2 get 4 pkts staterr value */
513 zero = _mm_xor_si128(dd_check, dd_check);
514 staterr = _mm_unpacklo_epi32(sterr_tmp1, sterr_tmp2);
516 /* D.3 copy final 3,4 data to rx_pkts */
517 _mm_storeu_si128((void *)&rx_pkts[pos+3]->rx_descriptor_fields1,
519 _mm_storeu_si128((void *)&rx_pkts[pos+2]->rx_descriptor_fields1,
522 /* C* extract and record EOP bit */
524 __m128i eop_shuf_mask = _mm_set_epi8(
525 0xFF, 0xFF, 0xFF, 0xFF,
526 0xFF, 0xFF, 0xFF, 0xFF,
527 0xFF, 0xFF, 0xFF, 0xFF,
528 0x04, 0x0C, 0x00, 0x08
531 /* and with mask to extract bits, flipping 1-0 */
532 __m128i eop_bits = _mm_andnot_si128(staterr, eop_check);
533 /* the staterr values are not in order, as the count
534 * count of dd bits doesn't care. However, for end of
535 * packet tracking, we do care, so shuffle. This also
536 * compresses the 32-bit values to 8-bit
538 eop_bits = _mm_shuffle_epi8(eop_bits, eop_shuf_mask);
539 /* store the resulting 32-bit value */
540 *(int *)split_packet = _mm_cvtsi128_si32(eop_bits);
541 split_packet += RTE_FM10K_DESCS_PER_LOOP;
543 /* zero-out next pointers */
544 rx_pkts[pos]->next = NULL;
545 rx_pkts[pos + 1]->next = NULL;
546 rx_pkts[pos + 2]->next = NULL;
547 rx_pkts[pos + 3]->next = NULL;
550 /* C.3 calc available number of desc */
551 staterr = _mm_and_si128(staterr, dd_check);
552 staterr = _mm_packs_epi32(staterr, zero);
554 /* D.3 copy final 1,2 data to rx_pkts */
555 _mm_storeu_si128((void *)&rx_pkts[pos+1]->rx_descriptor_fields1,
557 _mm_storeu_si128((void *)&rx_pkts[pos]->rx_descriptor_fields1,
560 fm10k_desc_to_pktype_v(descs0, &rx_pkts[pos]);
562 /* C.4 calc avaialbe number of desc */
563 var = __builtin_popcountll(_mm_cvtsi128_si64(staterr));
565 if (likely(var != RTE_FM10K_DESCS_PER_LOOP))
569 /* Update our internal tail pointer */
570 rxq->next_dd = (uint16_t)(rxq->next_dd + nb_pkts_recd);
571 rxq->next_dd = (uint16_t)(rxq->next_dd & (rxq->nb_desc - 1));
572 rxq->rxrearm_nb = (uint16_t)(rxq->rxrearm_nb + nb_pkts_recd);
577 /* vPMD receive routine
580 * - don't support ol_flags for rss and csum err
583 fm10k_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
586 return fm10k_recv_raw_pkts_vec(rx_queue, rx_pkts, nb_pkts, NULL);
589 static inline uint16_t
590 fm10k_reassemble_packets(struct fm10k_rx_queue *rxq,
591 struct rte_mbuf **rx_bufs,
592 uint16_t nb_bufs, uint8_t *split_flags)
594 struct rte_mbuf *pkts[RTE_FM10K_MAX_RX_BURST]; /*finished pkts*/
595 struct rte_mbuf *start = rxq->pkt_first_seg;
596 struct rte_mbuf *end = rxq->pkt_last_seg;
597 unsigned pkt_idx, buf_idx;
599 for (buf_idx = 0, pkt_idx = 0; buf_idx < nb_bufs; buf_idx++) {
601 /* processing a split packet */
602 end->next = rx_bufs[buf_idx];
604 start->pkt_len += rx_bufs[buf_idx]->data_len;
607 if (!split_flags[buf_idx]) {
608 /* it's the last packet of the set */
609 #ifdef RTE_LIBRTE_FM10K_RX_OLFLAGS_ENABLE
610 start->hash = end->hash;
611 start->ol_flags = end->ol_flags;
612 start->packet_type = end->packet_type;
614 pkts[pkt_idx++] = start;
618 /* not processing a split packet */
619 if (!split_flags[buf_idx]) {
620 /* not a split packet, save and skip */
621 pkts[pkt_idx++] = rx_bufs[buf_idx];
624 end = start = rx_bufs[buf_idx];
628 /* save the partial packet for next time */
629 rxq->pkt_first_seg = start;
630 rxq->pkt_last_seg = end;
631 memcpy(rx_bufs, pkts, pkt_idx * (sizeof(*pkts)));
636 * vPMD receive routine that reassembles scattered packets
639 * - don't support ol_flags for rss and csum err
640 * - nb_pkts > RTE_FM10K_MAX_RX_BURST, only scan RTE_FM10K_MAX_RX_BURST
644 fm10k_recv_scattered_pkts_vec(void *rx_queue,
645 struct rte_mbuf **rx_pkts,
648 struct fm10k_rx_queue *rxq = rx_queue;
649 uint8_t split_flags[RTE_FM10K_MAX_RX_BURST] = {0};
652 /* Split_flags only can support max of RTE_FM10K_MAX_RX_BURST */
653 nb_pkts = RTE_MIN(nb_pkts, RTE_FM10K_MAX_RX_BURST);
654 /* get some new buffers */
655 uint16_t nb_bufs = fm10k_recv_raw_pkts_vec(rxq, rx_pkts, nb_pkts,
660 /* happy day case, full burst + no packets to be joined */
661 const uint64_t *split_fl64 = (uint64_t *)split_flags;
663 if (rxq->pkt_first_seg == NULL &&
664 split_fl64[0] == 0 && split_fl64[1] == 0 &&
665 split_fl64[2] == 0 && split_fl64[3] == 0)
668 /* reassemble any packets that need reassembly*/
669 if (rxq->pkt_first_seg == NULL) {
670 /* find the first split flag, and only reassemble then*/
671 while (i < nb_bufs && !split_flags[i])
676 return i + fm10k_reassemble_packets(rxq, &rx_pkts[i], nb_bufs - i,
680 static const struct fm10k_txq_ops vec_txq_ops = {
681 .reset = fm10k_reset_tx_queue,
684 void __attribute__((cold))
685 fm10k_txq_vec_setup(struct fm10k_tx_queue *txq)
687 txq->ops = &vec_txq_ops;
690 int __attribute__((cold))
691 fm10k_tx_vec_condition_check(struct fm10k_tx_queue *txq)
693 /* Vector TX can't offload any features yet */
694 if ((txq->txq_flags & FM10K_SIMPLE_TX_FLAG) != FM10K_SIMPLE_TX_FLAG)
704 vtx1(volatile struct fm10k_tx_desc *txdp,
705 struct rte_mbuf *pkt, uint64_t flags)
707 __m128i descriptor = _mm_set_epi64x(flags << 56 |
708 pkt->vlan_tci << 16 | pkt->data_len,
710 _mm_store_si128((__m128i *)txdp, descriptor);
714 vtx(volatile struct fm10k_tx_desc *txdp,
715 struct rte_mbuf **pkt, uint16_t nb_pkts, uint64_t flags)
719 for (i = 0; i < nb_pkts; ++i, ++txdp, ++pkt)
720 vtx1(txdp, *pkt, flags);
723 static inline int __attribute__((always_inline))
724 fm10k_tx_free_bufs(struct fm10k_tx_queue *txq)
726 struct rte_mbuf **txep;
731 struct rte_mbuf *m, *free[RTE_FM10K_TX_MAX_FREE_BUF_SZ];
733 /* check DD bit on threshold descriptor */
734 flags = txq->hw_ring[txq->next_dd].flags;
735 if (!(flags & FM10K_TXD_FLAG_DONE))
740 /* First buffer to free from S/W ring is at index
741 * next_dd - (rs_thresh-1)
743 txep = &txq->sw_ring[txq->next_dd - (n - 1)];
744 m = __rte_pktmbuf_prefree_seg(txep[0]);
745 if (likely(m != NULL)) {
748 for (i = 1; i < n; i++) {
749 m = __rte_pktmbuf_prefree_seg(txep[i]);
750 if (likely(m != NULL)) {
751 if (likely(m->pool == free[0]->pool))
754 rte_mempool_put_bulk(free[0]->pool,
755 (void *)free, nb_free);
761 rte_mempool_put_bulk(free[0]->pool, (void **)free, nb_free);
763 for (i = 1; i < n; i++) {
764 m = __rte_pktmbuf_prefree_seg(txep[i]);
766 rte_mempool_put(m->pool, m);
770 /* buffers were freed, update counters */
771 txq->nb_free = (uint16_t)(txq->nb_free + txq->rs_thresh);
772 txq->next_dd = (uint16_t)(txq->next_dd + txq->rs_thresh);
773 if (txq->next_dd >= txq->nb_desc)
774 txq->next_dd = (uint16_t)(txq->rs_thresh - 1);
776 return txq->rs_thresh;
779 static inline void __attribute__((always_inline))
780 tx_backlog_entry(struct rte_mbuf **txep,
781 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
785 for (i = 0; i < (int)nb_pkts; ++i)
786 txep[i] = tx_pkts[i];
790 fm10k_xmit_pkts_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
793 struct fm10k_tx_queue *txq = (struct fm10k_tx_queue *)tx_queue;
794 volatile struct fm10k_tx_desc *txdp;
795 struct rte_mbuf **txep;
796 uint16_t n, nb_commit, tx_id;
797 uint64_t flags = FM10K_TXD_FLAG_LAST;
798 uint64_t rs = FM10K_TXD_FLAG_RS | FM10K_TXD_FLAG_LAST;
801 /* cross rx_thresh boundary is not allowed */
802 nb_pkts = RTE_MIN(nb_pkts, txq->rs_thresh);
804 if (txq->nb_free < txq->free_thresh)
805 fm10k_tx_free_bufs(txq);
807 nb_commit = nb_pkts = (uint16_t)RTE_MIN(txq->nb_free, nb_pkts);
808 if (unlikely(nb_pkts == 0))
811 tx_id = txq->next_free;
812 txdp = &txq->hw_ring[tx_id];
813 txep = &txq->sw_ring[tx_id];
815 txq->nb_free = (uint16_t)(txq->nb_free - nb_pkts);
817 n = (uint16_t)(txq->nb_desc - tx_id);
818 if (nb_commit >= n) {
819 tx_backlog_entry(txep, tx_pkts, n);
821 for (i = 0; i < n - 1; ++i, ++tx_pkts, ++txdp)
822 vtx1(txdp, *tx_pkts, flags);
824 vtx1(txdp, *tx_pkts++, rs);
826 nb_commit = (uint16_t)(nb_commit - n);
829 txq->next_rs = (uint16_t)(txq->rs_thresh - 1);
831 /* avoid reach the end of ring */
832 txdp = &(txq->hw_ring[tx_id]);
833 txep = &txq->sw_ring[tx_id];
836 tx_backlog_entry(txep, tx_pkts, nb_commit);
838 vtx(txdp, tx_pkts, nb_commit, flags);
840 tx_id = (uint16_t)(tx_id + nb_commit);
841 if (tx_id > txq->next_rs) {
842 txq->hw_ring[txq->next_rs].flags |= FM10K_TXD_FLAG_RS;
843 txq->next_rs = (uint16_t)(txq->next_rs + txq->rs_thresh);
846 txq->next_free = tx_id;
848 FM10K_PCI_REG_WRITE(txq->tail_ptr, txq->next_free);
853 static void __attribute__((cold))
854 fm10k_reset_tx_queue(struct fm10k_tx_queue *txq)
856 static const struct fm10k_tx_desc zeroed_desc = {0};
857 struct rte_mbuf **txe = txq->sw_ring;
860 /* Zero out HW ring memory */
861 for (i = 0; i < txq->nb_desc; i++)
862 txq->hw_ring[i] = zeroed_desc;
864 /* Initialize SW ring entries */
865 for (i = 0; i < txq->nb_desc; i++)
868 txq->next_dd = (uint16_t)(txq->rs_thresh - 1);
869 txq->next_rs = (uint16_t)(txq->rs_thresh - 1);
873 /* Always allow 1 descriptor to be un-allocated to avoid
874 * a H/W race condition
876 txq->nb_free = (uint16_t)(txq->nb_desc - 1);
877 FM10K_PCI_REG_WRITE(txq->tail_ptr, 0);